Skip to content

Commit

Permalink
gitignore + workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
svdgoor committed Apr 22, 2023
1 parent be597a2 commit aba1ad1
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 4 deletions.
163 changes: 163 additions & 0 deletions .github/workflows/prerelease-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
name: Prerelease on tag

env:
# Name of the rust project, which is used to find the executable
# This is the name of the project in Cargo.toml
# Must be consistent with the name of the project in Cargo.toml, otherwise the executable will not be found
OUTPUT_NAME: mcsm
CARGO_TERM_COLOR: always

on:
push:
tags:
- 'p*'

jobs:

build_and_release_windows:
name: Build and Release Windows

runs-on: windows-latest

# Set environment variables, which are used in the job
env:
RELEASE_NAME_WIN: "${{ github.event.repository.name }}-${{ github.ref_name }}-Windows"
OUTPUT_DIR: "./target/release"

steps:
# Make available the code in the repository to the job
- uses: actions/checkout@v3

# Build the release
- name: Build Release
run: cargo build --release

# Rename the artifact, so it has the correct name
- name: Rename Artifact
run: mv ${{ env.OUTPUT_DIR }}/${{ env.OUTPUT_NAME }}.exe ${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_WIN }}.exe

# Create a release on Github, with the artifacts, which can be updated from other jobs
- name: Add Artifact To Github Release
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_WIN }}.exe" # The artifact to add to the release
replacesArtifacts: false # If the artifact already exists, replace it
token: ${{ secrets.GITHUB_TOKEN }} # The token to use to authenticate with Github
allowUpdates: true # Allow the release to be updated
generateReleaseNotes: true # Generate release notes from the commits
draft: true # If the release should be a draft
prerelease: true # If the release should be a pre-release
artifactErrorsFailBuild: true # If the build should fail if the artifact cannot be added to the release
updateOnlyUnreleased: true # If the build should fail if the release is not a draft or pre-release

# Upload the artifact to the job, so it can be downloaded from the job
- name: Add Artifact To Action Job
uses: actions/upload-artifact@v3
with:
name: "${{ env.RELEASE_NAME_WIN }}.exe"
path: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_WIN }}.exe"
retention-days: 5

build_and_release_linux:
name: Build and Release Linux

runs-on: ubuntu-latest

env:
RELEASE_NAME_LINUX: "${{ github.event.repository.name }}-${{ github.ref_name }}-Linux"
OUTPUT_DIR: "./target/release"

steps:
- uses: actions/checkout@v3 # Same as with Windows

# Install required tools for Linux
- name: Install required tools
run: sudo apt install libdbus-1-dev pkg-config libudev-dev

- name: Build Release # Same as with Windows
run: cargo build --release

- name: Rename Artifact # Same as with Windows
run: mv ${{ env.OUTPUT_DIR }}/${{ env.OUTPUT_NAME }} ${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_LINUX }}

- name: Add Artifact To Github Release # Same as with Windows
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_LINUX }}"
replacesArtifacts: false
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
generateReleaseNotes: true
draft: true
prerelease: true
artifactErrorsFailBuild: true
updateOnlyUnreleased: true

- name: Add Artifact To Action Job # Same as with Windows
uses: actions/upload-artifact@v3
with:
name: "${{ env.RELEASE_NAME_LINUX }}"
path: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_LINUX }}"
retention-days: 5

build_and_release_macos:
name: Build and Release MacOS

runs-on: macos-latest

env:
RELEASE_NAME_MACOS: "${{ github.event.repository.name }}-${{ github.ref_name }}-MacOS"
OUTPUT_DIR: "./target/aarch64-apple-darwin/release"

steps:
- uses: actions/checkout@v3 # Same as with Windows

# Install required target for MacOS
- name: Install required target
run: rustup target add aarch64-apple-darwin

- name: Build Release # Same as with Windows
run: cargo build --verbose --release --target=aarch64-apple-darwin # We need to specify the target for MacOS

- name: Rename Artifact # Same as with Windows
run: mv ${{ env.OUTPUT_DIR }}/${{ env.OUTPUT_NAME }} ${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_MACOS }}

- name: Add Artifact To Github Release # Same as with Windows
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_MACOS }}"
replacesArtifacts: false
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
generateReleaseNotes: true
draft: true
prerelease: true
artifactErrorsFailBuild: true
updateOnlyUnreleased: true

- name: Add Artifact To Action Job # Same as with Windows
uses: actions/upload-artifact@v3
with:
name: "${{ env.RELEASE_NAME_MACOS }}"
path: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_MACOS }}"
retention-days: 5

release:
name: Release

# Depends on the build jobs
needs: [build_and_release_windows, build_and_release_linux, build_and_release_macos]

runs-on: ubuntu-latest

steps:
- name: Release Github Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
makeLatest: false # Prevent the release from being marked as latest
updateOnlyUnreleased: true
draft: false # The release is no longer a draft
prerelease: true
generateReleaseNotes: true
182 changes: 182 additions & 0 deletions .github/workflows/release-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: Release on tag

env:
# Name of the rust project, which is used to find the executable
# This is the name of the project in Cargo.toml
# Must be consistent with the name of the project in Cargo.toml, otherwise the executable will not be found
OUTPUT_NAME: mcsm
CARGO_TERM_COLOR: always

on:
push:
tags:
- 'v*'

jobs:

build_and_release_windows:
name: Build and Release Windows

runs-on: windows-latest

# Set environment variables, which are used in the job
env:
RELEASE_NAME_WIN: "${{ github.event.repository.name }}-${{ github.ref_name }}-Windows"
OUTPUT_DIR: "./target/release"

steps:
# Make available the code in the repository to the job
- uses: actions/checkout@v3

# Replace version in cargo.toml
- name: Set Cargo Version
run: |
$version = $env:GITHUB_REF -replace '^refs/tags/v', ''
$content = Get-Content -Path Cargo.toml
$content = $content -replace 'version = "0.0.0"', "version = ""$version"""
$content | Set-Content -Path Cargo.toml
# Build the release
- name: Build Release
run: cargo build --release

# Rename the artifact, so it has the correct name
- name: Rename Artifact
run: mv ${{ env.OUTPUT_DIR }}/${{ env.OUTPUT_NAME }}.exe ${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_WIN }}.exe

# Create a release on Github, with the artifacts, which can be updated from other jobs
- name: Add Artifact To Github Release
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_WIN }}.exe" # The artifact to add to the release
replacesArtifacts: false # If the artifact already exists, replace it
token: ${{ secrets.GITHUB_TOKEN }} # The token to use to authenticate with Github
allowUpdates: true # Allow the release to be updated
generateReleaseNotes: true # Generate release notes from the commits
draft: true # If the release should be a draft
artifactErrorsFailBuild: true # If the build should fail if the artifact cannot be added to the release
updateOnlyUnreleased: true # If the build should fail if the release is not a draft or pre-release

# Upload the artifact to the job, so it can be downloaded from the job
- name: Add Artifact To Action Job
uses: actions/upload-artifact@v3
with:
name: "${{ env.RELEASE_NAME_WIN }}.exe"
path: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_WIN }}.exe"
retention-days: 5

build_and_release_linux:
name: Build and Release Linux

runs-on: ubuntu-latest

env:
RELEASE_NAME_LINUX: "${{ github.event.repository.name }}-${{ github.ref_name }}-Linux"
OUTPUT_DIR: "./target/release"

steps:
- uses: actions/checkout@v3 # Same as with Windows

# Install required tools for Linux
- name: Install required tools
run: sudo apt install libdbus-1-dev pkg-config libudev-dev

# Replace version in cargo.toml
- name: Set Cargo Version
# Assign to variable 'version' in Cargo.toml the version without the prefix 'v'
run: |
version=$(echo $GITHUB_REF | sed 's/refs\/tags\///g' | sed 's/v//g')
sed -i "s/version = \"0.0.0\"/version = \"$version\"/g" Cargo.toml
- name: Build Release # Same as with Windows
run: cargo build --release

- name: Rename Artifact # Same as with Windows
run: mv ${{ env.OUTPUT_DIR }}/${{ env.OUTPUT_NAME }} ${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_LINUX }}

- name: Add Artifact To Github Release # Same as with Windows
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_LINUX }}"
replacesArtifacts: false
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
generateReleaseNotes: true
draft: true
artifactErrorsFailBuild: true
updateOnlyUnreleased: true

- name: Add Artifact To Action Job # Same as with Windows
uses: actions/upload-artifact@v3
with:
name: "${{ env.RELEASE_NAME_LINUX }}"
path: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_LINUX }}"
retention-days: 5

build_and_release_macos:
name: Build and Release MacOS

runs-on: macos-latest

env:
RELEASE_NAME_MACOS: "${{ github.event.repository.name }}-${{ github.ref_name }}-MacOS"
OUTPUT_DIR: "./target/aarch64-apple-darwin/release"

steps:
- uses: actions/checkout@v3 # Same as with Windows

# Replace version in cargo.toml
- name: Set Cargo Version
# Assign to variable 'version' in Cargo.toml the version without the prefix 'v'
# Use MacOS commands
run: |
version=$(echo $GITHUB_REF | sed 's/refs\/tags\///g' | sed 's/v//g')
sed -i '' "s/version = \"0.0.0\"/version = \"$version\"/g" Cargo.toml
# Install required target for MacOS
- name: Install required target
run: rustup target add aarch64-apple-darwin

- name: Build Release # Same as with Windows
run: cargo build --verbose --release --target=aarch64-apple-darwin # We need to specify the target for MacOS

- name: Rename Artifact # Same as with Windows
run: mv ${{ env.OUTPUT_DIR }}/${{ env.OUTPUT_NAME }} ${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_MACOS }}

- name: Add Artifact To Github Release # Same as with Windows
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_MACOS }}"
replacesArtifacts: false
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
generateReleaseNotes: true
draft: true
artifactErrorsFailBuild: true
updateOnlyUnreleased: true

- name: Add Artifact To Action Job # Same as with Windows
uses: actions/upload-artifact@v3
with:
name: "${{ env.RELEASE_NAME_MACOS }}"
path: "${{ env.OUTPUT_DIR }}/${{ env.RELEASE_NAME_MACOS }}"
retention-days: 5

release:
name: Release

# Depends on the build jobs
needs: [build_and_release_windows, build_and_release_linux, build_and_release_macos]

runs-on: ubuntu-latest

steps:
- name: Release Github Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
makeLatest: true
updateOnlyUnreleased: true
draft: false # The release is no longer a draft
generateReleaseNotes: true
21 changes: 17 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# Everything
*

# Except for the following
!LICENSE
!README.md
!run.py

## Source code
!src
!src/**

# The cargo files
!Cargo.toml
!server.toml

## Github workflows
!.github
!.github/**

## Batch scripts
!*.bat

## The license and readme
!LICENSE
!README.md

## The submodules
!plugins/Iris/packs/overworld
!plugins/Iris/Iris

0 comments on commit aba1ad1

Please sign in to comment.