From 3f0961396f23952747b6a235b9fd97fb3948569c Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Sat, 1 Apr 2023 11:12:19 -0300 Subject: [PATCH] GitHub Actions workflow improvements: - Build tags and create releases for them in the main repository - Do not build non-official builds for tags - Package Release Notes with the builds - Modularize actions --- .github/actions/create-release/action.yml | 87 +++++ .github/actions/get-release-notes/action.yml | 21 ++ .github/actions/release-info/action.yml | 58 ++++ .github/workflows/main.yml | 314 +++---------------- 4 files changed, 202 insertions(+), 278 deletions(-) create mode 100644 .github/actions/create-release/action.yml create mode 100644 .github/actions/get-release-notes/action.yml create mode 100644 .github/actions/release-info/action.yml diff --git a/.github/actions/create-release/action.yml b/.github/actions/create-release/action.yml new file mode 100644 index 0000000000..8dbbf03ef6 --- /dev/null +++ b/.github/actions/create-release/action.yml @@ -0,0 +1,87 @@ +# TODO: Replace asfernandes/action-gh-release@master by softprops/action-gh-release@v1 +# once https://github.com/softprops/action-gh-release/pull/343 is merged. + +name: Create release +description: Create release + +inputs: + token: + description: Token + required: true + deletePatterns: + description: Pattern to delete old assets + required: true + uploadFiles: + description: Files to upload + required: true + +runs: + using: composite + steps: + - name: Get release info + id: release-info + if: github.event.head_commit.message == 'increment build number' || github.ref_type == 'tag' + uses: ./.github/actions/release-info + + - name: Delete old assets + uses: mknejp/delete-release-assets@v1 + if: steps.release-info.outputs.artifacts-tag && github.ref_type != 'tag' + with: + repository: ${{ + (steps.release-info.outputs.artifacts-repository != github.repository && + steps.release-info.outputs.artifacts-repository) || + null + }} + token: ${{ + (steps.release-info.outputs.artifacts-repository != github.repository && + inputs.token) || + github.token + }} + tag: ${{ steps.release-info.outputs.artifacts-tag }} + fail-if-no-release: false + fail-if-no-assets: false + assets: ${{ inputs.deletePatterns }} + + - name: Release + id: release_try1 + uses: asfernandes/action-gh-release@master + if: steps.release-info.outputs.artifacts-tag + continue-on-error: true + with: + repository: ${{ + (steps.release-info.outputs.artifacts-repository != github.repository && + steps.release-info.outputs.artifacts-repository) || + null + }} + token: ${{ + (steps.release-info.outputs.artifacts-repository != github.repository && + inputs.token) || + github.token + }} + name: ${{ steps.release-info.outputs.artifacts-tag-description }} + tag_name: ${{ steps.release-info.outputs.artifacts-tag }} + prerelease: true + overwrite_files: github.ref_type != 'tag' + files: ${{ inputs.uploadFiles }} + + - name: Release (retry) + uses: asfernandes/action-gh-release@master + if: | + steps.release-info.outputs.artifacts-tag && + steps.release_try1.outcome == 'failure' + with: + repository: ${{ + (steps.release-info.outputs.artifacts-repository != github.repository && + steps.release-info.outputs.artifacts-repository) || + null + }} + token: ${{ + (steps.release-info.outputs.artifacts-repository != github.repository && + inputs.token) || + github.token + }} + name: ${{ steps.release-info.outputs.artifacts-tag-description }} + tag_name: ${{ steps.release-info.outputs.artifacts-tag }} + prerelease: true + overwrite_files: github.ref_type != 'tag' + files: ${{ inputs.uploadFiles }} diff --git a/.github/actions/get-release-notes/action.yml b/.github/actions/get-release-notes/action.yml new file mode 100644 index 0000000000..f2681fcc91 --- /dev/null +++ b/.github/actions/get-release-notes/action.yml @@ -0,0 +1,21 @@ +name: Get Release Notes +description: Get Release Notes + +runs: + using: composite + steps: + - name: Get release info + id: release-info + uses: ./.github/actions/release-info + + - id: filename + if: steps.release-info.outputs.version + shell: bash + run: | + echo "filename=Firebird-${{ steps.release-info.outputs.version }}-ReleaseNotes.pdf" >> $GITHUB_OUTPUT + + - id: copy-release-notes-file + if: steps.filename.outputs.filename + shell: bash + run: | + (cd doc && curl -OL https://firebirdsql.org/file/documentation/release_notes/${{ steps.filename.outputs.filename }}) diff --git a/.github/actions/release-info/action.yml b/.github/actions/release-info/action.yml new file mode 100644 index 0000000000..a26ef50385 --- /dev/null +++ b/.github/actions/release-info/action.yml @@ -0,0 +1,58 @@ +name: Get release info +description: Get release info + +outputs: + version: + description: Version + value: ${{ steps.version.outputs.version }} + artifacts-repository: + description: Artifacts repository + value: ${{ steps.artifacts-repository.outputs.artifacts-repository }} + artifacts-tag: + description: Artifacts tag + value: ${{ steps.artifacts-tag.outputs.tag }} + artifacts-tag-description: + description: Artifacts tag description + value: ${{ steps.artifacts-tag.outputs.tag-description }} + +runs: + using: composite + steps: + - id: version + if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') + shell: bash + run: | + version=$(echo ${{ github.ref_name }} | cut -c2-) + echo "version=$version" >> $GITHUB_OUTPUT + + - id: artifacts-repository + if: github.repository == 'FirebirdSQL/firebird' + shell: bash + run: | + repository=${{ + (github.ref_type == 'tag' && startsWith(github.ref_name, 'v') && github.repository) || + (github.ref_type == 'branch' && + (github.ref_name == 'master' || + (startsWith(github.ref_name, 'v') && endsWith(github.ref_name, '-release')) + ) && + 'FirebirdSQL/snapshots' + ) || + '' + }} + echo "artifacts-repository=$repository" >> $GITHUB_OUTPUT + + - id: artifacts-tag + if: steps.artifacts-repository.outputs.artifacts-repository + shell: bash + run: | + tag=${{ + (github.ref_type == 'tag' && github.ref_name) || + format('snapshot-{0}', github.ref_name) + }} + echo "tag=$tag" >> $GITHUB_OUTPUT + + tag_description="${{ + (github.ref_type == 'tag' && github.ref_name) || + format('Latest snapshots for {0}', github.ref_name) + }}" + echo "tag-description=$tag_description" >> $GITHUB_OUTPUT diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 510ce79d93..54666c895b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,7 @@ on: [push, pull_request] jobs: build-linux-ubuntu-x64-clang: + if: github.ref_type != 'tag' runs-on: ubuntu-20.04 steps: @@ -54,6 +55,9 @@ jobs: with: fetch-depth: 10 + - name: Get Release Notes + uses: ./.github/actions/get-release-notes + - name: Set up QEMU uses: docker/setup-qemu-action@v2 if: ${{ startsWith(matrix.arch, 'arm') }} @@ -75,54 +79,12 @@ jobs: name: firebird-linux-${{ matrix.arch }}-debugSymbols path: gen/Firebird-*-linux-${{ matrix.arch }}-debugSymbols.tar.gz - - name: Snapshot - prepare - id: snapshot_prepare - if: | - github.repository == 'FirebirdSQL/firebird' && - github.event.head_commit.message == 'increment build number' && - github.ref_name == 'master' - run: | - echo "snapshot_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT - - - name: Snapshot - delete old assets - uses: mknejp/delete-release-assets@v1 - if: steps.snapshot_prepare.outputs.snapshot_name + - name: Create release + uses: ./.github/actions/create-release with: - repository: FirebirdSQL/snapshots token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - tag: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - fail-if-no-release: false - fail-if-no-assets: false - assets: | - Firebird-*-linux-${{ matrix.arch }}*.tar.gz - - - name: Snapshot - release - id: snapshot_release_try1 - uses: softprops/action-gh-release@v1 - if: steps.snapshot_prepare.outputs.snapshot_name - continue-on-error: true - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/Firebird-*-linux-${{ matrix.arch }}*.tar.gz - - - name: Snapshot - release (retry) - uses: softprops/action-gh-release@v1 - if: | - steps.snapshot_prepare.outputs.snapshot_name && - steps.snapshot_release_try1.outcome == 'failure' - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/Firebird-*-linux-${{ matrix.arch }}*.tar.gz + deletePatterns: Firebird-*-linux-${{ matrix.arch }}*.tar.gz + uploadFiles: gen/Firebird-*-linux-${{ matrix.arch }}*.tar.gz build-src-bundle-docker: name: build-src-bundle-docker @@ -134,61 +96,23 @@ jobs: with: fetch-depth: 10 + - name: Get Release Notes + uses: ./.github/actions/get-release-notes + - name: Build run: | cd builds/docker/linux/x86-x64 ./run-src-bundle.sh - - name: Snapshot - prepare - id: snapshot_prepare - if: | - github.repository == 'FirebirdSQL/firebird' && - github.event.head_commit.message == 'increment build number' && - github.ref_name == 'master' - run: | - echo "snapshot_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT - - - name: Snapshot - delete old assets - uses: mknejp/delete-release-assets@v1 - if: steps.snapshot_prepare.outputs.snapshot_name + - name: Create release + uses: ./.github/actions/create-release with: - repository: FirebirdSQL/snapshots token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - tag: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - fail-if-no-release: false - fail-if-no-assets: false - assets: | - Firebird-*-source.tar.xz - - - name: Snapshot - release - id: snapshot_release_try1 - uses: softprops/action-gh-release@v1 - if: steps.snapshot_prepare.outputs.snapshot_name - continue-on-error: true - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/Firebird-*-source.tar.xz - - - name: Snapshot - release (retry) - uses: softprops/action-gh-release@v1 - if: | - steps.snapshot_prepare.outputs.snapshot_name && - steps.snapshot_release_try1.outcome == 'failure' - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/Firebird-*-source.tar.xz + deletePatterns: Firebird-*-source.tar.xz + uploadFiles: gen/Firebird-*-source.tar.xz build-alpine-x64: + if: github.ref_type != 'tag' runs-on: ubuntu-20.04 container: alpine:3.14 @@ -217,6 +141,7 @@ jobs: path: gen/Firebird-*-linux-x64.tar.gz build-windows: + if: github.ref_type != 'tag' runs-on: ${{ matrix.os }} env: VS_VERSION: ${{ (matrix.os == 'windows-2019' && '2019' || (matrix.os == 'windows-2022' && '2022' || '')) }} @@ -273,8 +198,6 @@ jobs: build-windows-docker: runs-on: windows-2022 - env: - VS_VERSION: ${{ (matrix.os == 'windows-2019' && '2019' || (matrix.os == 'windows-2022' && '2022' || '')) }} strategy: fail-fast: false @@ -287,6 +210,9 @@ jobs: with: fetch-depth: 10 + - name: Get Release Notes + uses: ./.github/actions/get-release-notes + - name: Build id: build shell: cmd @@ -323,59 +249,17 @@ jobs: name: firebird-windows-${{ matrix.platform }}-withDebugSymbols-installer path: builds/install_images/*-windows-${{ matrix.platform }}-withDebugSymbols.exe - - name: Snapshot - prepare - id: snapshot_prepare - if: | - github.repository == 'FirebirdSQL/firebird' && - github.event.head_commit.message == 'increment build number' && - github.ref_name == 'master' - shell: cmd - run: | - echo snapshot_name=${{ github.ref_name }}>> %GITHUB_OUTPUT% - - - name: Snapshot - delete old assets - uses: mknejp/delete-release-assets@v1 - if: steps.snapshot_prepare.outputs.snapshot_name + - name: Create release + uses: ./.github/actions/create-release with: - repository: FirebirdSQL/snapshots token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - tag: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - fail-if-no-release: false - fail-if-no-assets: false - assets: | + deletePatterns: | Firebird-*-windows-${{ steps.build.outputs.arch_suffix }}*.exe Firebird-*-windows-${{ steps.build.outputs.arch_suffix }}*.zip - - - name: Snapshot - release - id: snapshot_release_try1 - uses: softprops/action-gh-release@v1 - if: steps.snapshot_prepare.outputs.snapshot_name - continue-on-error: true - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | + uploadFiles: | builds/install_images/Firebird-*-windows-*.exe builds/install_images/Firebird-*-windows-*.zip - - name: Snapshot - release (retry) - uses: softprops/action-gh-release@v1 - if: | - steps.snapshot_prepare.outputs.snapshot_name && - steps.snapshot_release_try1.outcome == 'failure' - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - builds/install_images/Firebird-*windows-*.exe - builds/install_images/Firebird-*windows-*.zip - build-macos: runs-on: macos-latest @@ -505,54 +389,12 @@ jobs: name: firebird-macos path: gen/artifacts - - name: Snapshot - prepare - id: snapshot_prepare - if: | - github.repository == 'FirebirdSQL/firebird' && - github.event.head_commit.message == 'increment build number' && - github.ref_name == 'master' - run: | - echo "snapshot_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT - - - name: Snapshot - delete old assets - uses: mknejp/delete-release-assets@v1 - if: steps.snapshot_prepare.outputs.snapshot_name + - name: Create release + uses: ./.github/actions/create-release with: - repository: FirebirdSQL/snapshots token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - tag: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - fail-if-no-release: false - fail-if-no-assets: false - assets: | - Firebird-*-macos-x64*.pkg - - - name: Snapshot - release - id: snapshot_release_try1 - uses: softprops/action-gh-release@v1 - if: steps.snapshot_prepare.outputs.snapshot_name - continue-on-error: true - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/artifacts/Firebird-*-macos-x64*.pkg - - - name: Snapshot - release (retry) - uses: softprops/action-gh-release@v1 - if: | - steps.snapshot_prepare.outputs.snapshot_name && - steps.snapshot_release_try1.outcome == 'failure' - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/artifacts/Firebird-*-macos-x64*.pkg + deletePatterns: Firebird-*-macos-x64*.pkg + uploadFiles: gen/artifacts/Firebird-*-macos-x64*.pkg build-android-initial: name: build-android-${{ matrix.arch }}-initial @@ -686,54 +528,12 @@ jobs: with: name: firebird-android-initial-${{ matrix.arch }} - - name: Snapshot - prepare - id: snapshot_prepare - if: | - github.repository == 'FirebirdSQL/firebird' && - github.event.head_commit.message == 'increment build number' && - github.ref_name == 'master' - run: | - echo "snapshot_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT - - - name: Snapshot - delete old assets - uses: mknejp/delete-release-assets@v1 - if: steps.snapshot_prepare.outputs.snapshot_name + - name: Create release + uses: ./.github/actions/create-release with: - repository: FirebirdSQL/snapshots token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - tag: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - fail-if-no-release: false - fail-if-no-assets: false - assets: | - Firebird-*-android-${{ matrix.arch }}*.tar.gz - - - name: Snapshot - release - id: snapshot_release_try1 - uses: softprops/action-gh-release@v1 - if: steps.snapshot_prepare.outputs.snapshot_name - continue-on-error: true - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/Firebird-*-android-${{ matrix.arch }}*.tar.gz - - - name: Snapshot - release (retry) - uses: softprops/action-gh-release@v1 - if: | - steps.snapshot_prepare.outputs.snapshot_name && - steps.snapshot_release_try1.outcome == 'failure' - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - gen/Firebird-*-android-${{ matrix.arch }}*.tar.gz + deletePatterns: Firebird-*-android-${{ matrix.arch }}*.tar.gz + uploadFiles: gen/Firebird-*-android-${{ matrix.arch }}*.tar.gz build-android-aar: needs: build-android-final @@ -796,51 +596,9 @@ jobs: name: firebird-android-aar path: android/embedded/build/outputs/aar/Firebird-*-android-embedded.aar - - name: Snapshot - prepare - id: snapshot_prepare - if: | - github.repository == 'FirebirdSQL/firebird' && - github.event.head_commit.message == 'increment build number' && - github.ref_name == 'master' - run: | - echo "snapshot_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT - - - name: Snapshot - delete old assets - uses: mknejp/delete-release-assets@v1 - if: steps.snapshot_prepare.outputs.snapshot_name + - name: Create release + uses: ./.github/actions/create-release with: - repository: FirebirdSQL/snapshots token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - tag: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - fail-if-no-release: false - fail-if-no-assets: false - assets: | - Firebird-*-android-embedded.aar - - - name: Snapshot - release - id: snapshot_release_try1 - uses: softprops/action-gh-release@v1 - if: steps.snapshot_prepare.outputs.snapshot_name - continue-on-error: true - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - android/embedded/build/outputs/aar/Firebird-*-android-embedded.aar - - - name: Snapshot - release (retry) - uses: softprops/action-gh-release@v1 - if: | - steps.snapshot_prepare.outputs.snapshot_name && - steps.snapshot_release_try1.outcome == 'failure' - with: - repository: FirebirdSQL/snapshots - name: Latest snapshots for ${{ steps.snapshot_prepare.outputs.snapshot_name }} - tag_name: snapshot-${{ steps.snapshot_prepare.outputs.snapshot_name }} - prerelease: true - token: ${{ secrets.SNAPSHOT_RELEASE_TOKEN }} - files: | - android/embedded/build/outputs/aar/Firebird-*-android-embedded.aar + deletePatterns: Firebird-*-android-embedded.aar + uploadFiles: android/embedded/build/outputs/aar/Firebird-*-android-embedded.aar