From a56a248b6b46bfaab4201c653f84f402bc9c6f1e Mon Sep 17 00:00:00 2001 From: bd_ Date: Sat, 23 Sep 2023 20:20:19 +0900 Subject: [PATCH] ci: add auto-release-tagging workflow --- .github/workflows/build-release.yml | 93 ++++++++++++++++++++---- .github/workflows/check-semver-syntax.sh | 8 ++ .github/workflows/gameci.yml | 11 ++- 3 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/check-semver-syntax.sh diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index d222c1c0..257d596a 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -2,7 +2,6 @@ name: Build Release on: workflow_dispatch: - pull_request: push: branches: - main @@ -12,33 +11,88 @@ on: env: packageName: "nadena.dev.ndmf" -permissions: - contents: write jobs: - build: + run-tests: + needs: [prechecks] + if: needs.prechecks.outputs.need-new-tag == 'true' + uses: bdunderscore/ndmf/.github/workflows/gameci.yml@main + permissions: + checks: write + contents: read + secrets: inherit + prechecks: runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.prop }} + need-new-tag: ${{ steps.check-tag.outputs.need-new-tag }} steps: - name: Checkout uses: actions/checkout@v3 + - name: get version + run: | + echo version=$(jq -r .version package.json) >> $GITHUB_OUTPUT + echo current_version=$(jq -r .version package.json) >> $GITHUB_ENV + + - name: Check if version is tagged + id: check-tag + run: | + if git fetch origin $current_version --depth=1; then + echo "Version $current_version is already tagged" + echo "need-new-tag=false" >> $GITHUB_OUTPUT + else + echo "Version $current_version is not tagged" + echo "need-new-tag=true" >> $GITHUB_OUTPUT + fi + + - name: Verify that this is the first revision with this version + if: steps.check-tag.outputs.need-new-tag == 'true' + run: | + git fetch --unshallow + git checkout HEAD~ package.json + if [ "$(jq -r .version package.json)" == "$current_version" ]; then + echo "Error: Looks like we skipped the version bump commit." + exit 1 + fi + - name: Check semver syntax + if: steps.check-tag.outputs.need-new-tag == 'true' id: semver-check + run: | + chmod +x .github/workflows/*.sh + .github/workflows/check-semver-syntax.sh ${{ steps.version.outputs.prop }} + + - name: Check tag consistency if: startsWith(github.ref, 'refs/tags/') - env: - REF_NAME: ${{ github.ref }} run: | - if echo $REF_NAME | grep '[a-z]-[0-9]' && ! echo $REF_NAME | grep '^refs/tags/1\.5\.0-'; then - echo "Tag name does not follow semver prerelease syntax: $REF_NAME" + if [ "${{ steps.version.outputs.prop }}" != "${GITHUB_REF##*/}" ]; then + echo "Version in package.json does not match tag name: ${{ steps.version.outputs.prop }} != ${GITHUB_REF##*/}" exit 1 fi - - name: get version + create-release: + needs: [prechecks, run-tests] + runs-on: ubuntu-latest + if: needs.prechecks.outputs.need-new-tag == 'true' || startsWith(github.ref, 'refs/tags/') + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Reexport version id: version - uses: notiz-dev/github-action-json-property@a5a9c668b16513c737c3e1f8956772c99c73f6e8 - with: - path: "package.json" - prop_path: "version" + run: | + echo "version=${{ needs.prechecks.outputs.version }}" >> $GITHUB_ENV + + # Re-check semver syntax in case this is being triggered by a manual tag push + - name: Check semver syntax + if: steps.check_tagged.outputs.need_tag == 'true' + id: semver-check + run: | + chmod +x .github/scripts/*.sh + .github/scripts/check-semver.sh ${{ steps.version.outputs.prop }} - name: Check tag consistency if: startsWith(github.ref, 'refs/tags/') @@ -48,8 +102,6 @@ jobs: exit 1 fi - - run: echo ${{steps.version.outputs.prop}} - - name: Set Environment Variables run: | echo "zipFile=${{ env.packageName }}-${{ steps.version.outputs.prop }}".zip >> $GITHUB_ENV @@ -71,14 +123,23 @@ jobs: with: name: package-zip path: ${{ env.zipFile }} + + - name: Create tag + if: needs.prechecks.outputs.need-new-tag == 'true' + run: | + git config user.name "Github Actions" + git config user.email "github-actions@nadena.dev" + git tag ${{ steps.version.outputs.prop }} + git push origin ${{ steps.version.outputs.prop }} - name: Make Release uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 - if: startsWith(github.ref, 'refs/tags/') + if: needs.prechecks.outputs.need-new-tag == 'true' || startsWith(github.ref, 'refs/tags/') with: draft: true generate_release_notes: true tag_name: ${{ steps.version.outputs.prop }} + name: ${{ steps.version.outputs.prop }} files: | ${{ env.zipFile }} package.json diff --git a/.github/workflows/check-semver-syntax.sh b/.github/workflows/check-semver-syntax.sh new file mode 100644 index 00000000..640ecb77 --- /dev/null +++ b/.github/workflows/check-semver-syntax.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -x + +if echo $1 | grep '[a-z]-[0-9]' > /dev/null; then + echo "Tag name does not follow semver prerelease syntax: $REF_NAME" + exit 1 +fi \ No newline at end of file diff --git a/.github/workflows/gameci.yml b/.github/workflows/gameci.yml index 06dbeb34..dc015dea 100644 --- a/.github/workflows/gameci.yml +++ b/.github/workflows/gameci.yml @@ -32,6 +32,10 @@ on: # whatever permissions we assign. pull_request_target: {} workflow_dispatch: {} + workflow_call: + secrets: + UNITY_LICENSE: + required: true # pull_request_target grants access to a privileged GITHUB_TOKEN by default, revoke this permissions: {} @@ -40,7 +44,8 @@ jobs: build-and-test: strategy: matrix: - unity_version: [ auto, 2022.3.5f1 ] + #unity_version: [ auto, 2022.3.5f1 ] + unity_version: [ auto ] runs-on: ubuntu-latest permissions: checks: write @@ -66,7 +71,7 @@ jobs: - uses: actions/cache@v3 with: path: Library - key: Library-${{ matrix.projectPath }} + key: Library-${{ matrix.unity_version }} restore-keys: Library- - uses: game-ci/unity-test-runner@v3 @@ -81,8 +86,6 @@ jobs: githubToken: ${{ github.token }} coverageOptions: generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;assemblyFilters:+nadena.dev.* customParameters: -nographics -assemblyNames nadena.dev.ndmf.UnitTests - targetPlatform: StandaloneWindows - - uses: actions/upload-artifact@v3 if: always()