From 955f2fa6ffc4420455bf797423910a2ca9fff208 Mon Sep 17 00:00:00 2001 From: Dominique CLAUSE Date: Tue, 15 Oct 2024 12:36:49 +0200 Subject: [PATCH] Add release github action. --- .github/actions/build_frontend/action.yml | 27 +++ .github/workflows/build_backend.yml | 1 - .github/workflows/build_frontend.yml | 24 +-- .github/workflows/coverage_backend.yml | 1 - .github/workflows/release.yml | 190 ++++++++++++++++++++++ .github/workflows/test_backend.yml | 1 - backend/Cross.toml | 23 +++ 7 files changed, 242 insertions(+), 25 deletions(-) create mode 100644 .github/actions/build_frontend/action.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/build_frontend/action.yml b/.github/actions/build_frontend/action.yml new file mode 100644 index 0000000..2090506 --- /dev/null +++ b/.github/actions/build_frontend/action.yml @@ -0,0 +1,27 @@ +name: 'FRONTEND build composite action' +description: 'Builds the frontend' +runs: + using: "composite" + steps: + - name: Setup Node.js + uses: actions/setup-node@v4 + + - name: Install pnpm + working-directory: ./frontend + run: npm install --global pnpm + + - name: Cache .pnpm-store + uses: actions/cache@v4 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm- + + - name: Install dependencies + working-directory: ./frontend + run: pnpm install + + - name: Run FRONTEND pnpm build + working-directory: ./frontend + run: pnpm build \ No newline at end of file diff --git a/.github/workflows/build_backend.yml b/.github/workflows/build_backend.yml index e6cf14a..4c5f53d 100644 --- a/.github/workflows/build_backend.yml +++ b/.github/workflows/build_backend.yml @@ -26,7 +26,6 @@ jobs: run: | sudo apt update sudo apt install -y pkg-config libudev-dev libasound2-dev - if: contains(matrix.os, 'ubuntu') - name: Run BACKEND cargo build working-directory: ./backend diff --git a/.github/workflows/build_frontend.yml b/.github/workflows/build_frontend.yml index b8b33c8..5102c88 100644 --- a/.github/workflows/build_frontend.yml +++ b/.github/workflows/build_frontend.yml @@ -11,7 +11,6 @@ env: jobs: build: - name: ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -20,26 +19,7 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - - - name: Install pnpm - working-directory: ./frontend - run: npm install --global pnpm - - - name: Cache .pnpm-store - uses: actions/cache@v4 with: - path: ~/.pnpm-store - key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm- - - - name: Install dependencies - working-directory: ./frontend - run: pnpm install + ref: 'develop' - - name: Run FRONTEND pnpm build - working-directory: ./frontend - run: pnpm build \ No newline at end of file + - uses: ./github/actions/build_frontend \ No newline at end of file diff --git a/.github/workflows/coverage_backend.yml b/.github/workflows/coverage_backend.yml index 7575841..0ea678b 100644 --- a/.github/workflows/coverage_backend.yml +++ b/.github/workflows/coverage_backend.yml @@ -31,7 +31,6 @@ jobs: run: | sudo apt update sudo apt install -y pkg-config libudev-dev libasound2-dev - if: contains(matrix.os, 'ubuntu') - name: Generate code coverage working-directory: ./backend diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..824cdac --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,190 @@ +name: Release + +on: + push: + branches: [ "releases" ] + tags: + # Regex for a version number such as 0.2.1 + - "[0-9]+.[0-9]+.[0-9]+" + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + inputs: + tagname: + description: "Tag name for release" + required: false + default: nightly + +jobs: + + # Build the tagname and branch + prepare: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.output.outputs.version }} + branch: ${{ steps.output.outputs.branch }} + steps: + # Manual input on 'workflow_dispatch' + - if: github.event_name == 'workflow_dispatch' + run: | + { + echo 'VERSION=${{ github.event.inputs.tagname }}' + echo 'BRANCH=develop' + } | tee -a $GITHUB_ENV + + # Based on tag name when pushed on 'releases' branch. + - if: github.event_name == 'push' + run: | + TAGNAME=${{ github.ref }} + { + echo 'VERSION=${TAGNAME#refs/tags/}' + echo 'BRANCH=releases' + } | tee -a $GITHUB_ENV + + - id: output + run: | + { + echo 'version=$VERSION' + echo 'branch=$BRANCH' + } | tee -a $GITHUB_OUTPUT + + website: + name: Build FRONTEND + runs-on: windows-latest + needs: prepare + steps: + + - name: Checkout sources + uses: actions/checkout@v4 + with: + ref: ${{ needs.prepare.outputs.branch }} + + - uses: ./github/actions/build_frontend + + - name: Upload Frontend + uses: actions/upload-artifact@v4 + with: + name: website + path: ./frontend/dist/ + retention-days: 1 + + backend: + name: Cross-platform build BACKEND + runs-on: windows-latest + needs: + - prepare + - website + env: + CARGO_TERM_COLOR: always + CROSS_CONFIG: ./backend/Cross.toml + + strategy: + matrix: + include: + - target: x86_64-unknown-linux-gnu + - target: x86_64-apple-darwin + - target: x86_64-pc-windows-gnu + - target: aarch64-unknown-linux-gnu + - target: armv7-unknown-linux-gnueabihf + + steps: + - name: Clone repository + uses: actions/checkout@v4 + with: + ref: ${{ needs.prepare.outputs.branch }} + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Compile BACKEND + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --verbose --release --manifest-path "./backend/Cargo.toml" --target ${{ matrix.target }} + + - name: Download website + uses: actions/download-artifact@v4 + with: + name: website + + - name: Build archive + shell: bash + run: | + binary_name="hermes-studio" + + # Build a directory for this version + dirname="$binary_name-${{ needs.prepare.outputs.version }}-${{ matrix.target }}" + mkdir "$dirname" + + # Move the FRONTEND website into the directory + mv "website/" "$dirname" + + # Move the release binary (BACKEND) into the directory + if [ "${{ matrix.os }}" = "windows-latest" ]; then + mv "target/${{ matrix.target }}/release/$binary_name.exe" "$dirname" + else + mv "target/${{ matrix.target }}/release/$binary_name" "$dirname" + fi + + # Compress the directory + if [ "${{ matrix.os }}" = "windows-latest" ]; then + 7z a "$dirname.zip" "$dirname" + echo "ASSET=$dirname.zip" >> $GITHUB_ENV + else + tar -czf "$dirname.tar.gz" "$dirname" + echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV + fi + + - name: Upload the archive + uses: actions/upload-artifact@v4 + with: + name: ${{ env.ASSET }} + path: ${{ env.ASSET }} + retention-days: 1 + + + publish: + name: Publish release + runs-on: windows-latest + needs: + - prepare + - backend + env: + GH_REPO: ${{ github.repository }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + + steps: + # Must perform checkout first, since it deletes the target directory + # before running, and would therefore delete the downloaded artifacts + - uses: actions/checkout@v4 + + - name: Retrieve all artifacts + uses: actions/download-artifact@v4 + with: + pattern: hermes-studio-* + + - if: needs.prepare.outputs.version == 'nightly' + run: | + { + echo 'SUBJECT=Hermes-Studio development build' + echo 'PRERELEASE=--prerelease' + } | tee -a $GITHUB_ENV + gh release delete nightly --yes || true + git push origin :nightly || true + + - if: needs.prepare.outputs.version != 'nightly' + run: | + { + echo 'SUBJECT=Hermes-Studio release build' + echo 'PRERELEASE=' + } | tee -a $GITHUB_ENV + + - name: Publish release + uses: softprops/action-gh-release@v2 + with: + files: hermes-studio-* \ No newline at end of file diff --git a/.github/workflows/test_backend.yml b/.github/workflows/test_backend.yml index a8d3e28..650476f 100644 --- a/.github/workflows/test_backend.yml +++ b/.github/workflows/test_backend.yml @@ -26,7 +26,6 @@ jobs: run: | sudo apt update sudo apt install -y pkg-config libudev-dev libasound2-dev - if: contains(matrix.os, 'ubuntu') - name: Run BACKEND all tests working-directory: ./backend diff --git a/backend/Cross.toml b/backend/Cross.toml index 7b6c069..877e8a5 100644 --- a/backend/Cross.toml +++ b/backend/Cross.toml @@ -1,4 +1,27 @@ +[build] +pre-build = [ + "apt-get update && apt-get install --assume-yes ", + "apt-get update && apt-get install -y pkg-config libudev-dev libasound2-dev", +] + +# Mac OS +[target.x86_64-apple-darwin] +pre-build = [] + +# Win OS +[target.x86_64-pc-windows-gnu] +pre-build = [] + +# raspberryPI OS 64bits [target.aarch64-unknown-linux-gnu] +pre-build = [ + "dpkg --add-architecture $CROSS_DEB_ARCH", + "apt-get update && apt-get install --assume-yes ", + "apt-get update && apt-get install -y pkg-config libudev-dev:$CROSS_DEB_ARCH libasound2-dev:$CROSS_DEB_ARCH", +] + +# raspberryPI OS 32bits +[target.armv7-unknown-linux-gnueabihf] pre-build = [ "dpkg --add-architecture $CROSS_DEB_ARCH", "apt-get update && apt-get install --assume-yes ",