diff --git a/.github/workflows/post-merge.yml b/.github/workflows/post-merge.yml index 3d87e49..2c5cf69 100644 --- a/.github/workflows/post-merge.yml +++ b/.github/workflows/post-merge.yml @@ -1,4 +1,4 @@ -name: Test and Tag +name: Post-merge Test and Release on: push: @@ -12,35 +12,103 @@ jobs: test: uses: ./.github/workflows/run-tests.yml - check-for-and-create-new-release: - name: Create new release tag if needed + check-for-release: + name: Check if release required runs-on: ubuntu-latest needs: - test - - permissions: - contents: write + outputs: + release: "${{ steps.tag-release.outputs.release }}" + version: "${{ steps.tag-release.outputs.version }}" steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - shell: bash + id: tag-release + name: tag-release run: | VERSION=$(yq -oy '.package.version' Cargo.toml) - echo "Checking for version $VERSION" - git tag --list - echo "With grep" - git tag --list | grep "^$VERSION\$" if git tag --list | grep "^$VERSION\$" >>/dev/null 2>&1; then echo "Version $VERSION already tagged, no release to complete" + echo "release=false" >> $GITHUB_OUTPUT exit 0 fi - echo "Continuing to create release tag" + echo "Continuing to create release tag for $VERSION" + + echo "release=true" >> $GITHUB_OUTPUT + echo "version=$VERSION" >> $GITHUB_OUTPUT + + build-and-upload: + if: ${{ needs.check-for-release.outputs.release == 'true' }} + needs: check-for-release + name: Build and Upload + + runs-on: ${{ matrix.os }} + + permissions: + contents: write + + strategy: + matrix: + include: + - build: linux + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + + - build: macos-x86_64 + os: macos-latest + target: x86_64-apple-darwin + + # Can build, but not test + - build: macos-arm64 + os: macos-latest + target: aarch64-apple-darwin - git config user.name BridgeBoard-PC-Boot-Patcher-AutoRelease + - build: windows + os: windows-latest + target: x86_64-pc-windows-gnu + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Build Release Binaries + shell: bash + run: | + cargo build --release --target ${{ matrix.target }} - git tag "$VERSION" - git push origin "$VERSION" + - name: Create Release Archives + shell: bash + run: | + binary_name="bridgeboard-pc-boot-patcher" + + dirname="$binary_name-${{ needs.check-for-release.outputs.version }}-${{ matrix.build }}" + mkdir "$dirname" + 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 + + 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: Release + uses: softprops/action-gh-release@v1 + with: + name: ${{ needs.check-for-release.outputs.version }} + tag_name: ${{ needs.check-for-release.outputs.version }} + generate_release_notes: true + files: | + ${{ env.ASSET }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 6219c09..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,81 +0,0 @@ -# Thanks to https://dzfrias.dev/blog/deploy-rust-cross-platform-github-actions on which -# most of this workflow was based -name: Create Release - -on: - push: - branches: - - main - tags: - - "[0-9]+.[0-9]+.[0-9]+" - -permissions: - contents: write - -jobs: - build-and-upload: - name: Build and Upload - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - include: - - build: linux - os: ubuntu-latest - target: x86_64-unknown-linux-gnu - - - build: macos-x86_64 - os: macos-latest - target: x86_64-apple-darwin - - # Can build, but not test - - build: macos-arm64 - os: macos-latest - target: aarch64-apple-darwin - - - build: windows - os: windows-latest - target: x86_64-pc-windows-gnu - steps: - - uses: actions/checkout@v4 - - - name: Get the release version from the tag - shell: bash - run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - - - uses: dtolnay/rust-toolchain@stable - with: - targets: ${{ matrix.target }} - - - name: Release build - shell: bash - run: | - cargo build --release --target ${{ matrix.target }} - - - name: Build archive - shell: bash - run: | - binary_name="bridgeboard-pc-boot-patcher" - - dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}" - mkdir "$dirname" - 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 - - 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: Release - uses: softprops/action-gh-release@v1 - with: - files: | - ${{ env.ASSET }}