Skip to content

Commit

Permalink
ci: add auto-release-tagging workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Sep 23, 2023
1 parent e72c55c commit 41e3034
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 20 deletions.
93 changes: 77 additions & 16 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Build Release

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
Expand All @@ -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/')
Expand All @@ -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
Expand All @@ -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 "[email protected]"
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
8 changes: 8 additions & 0 deletions .github/workflows/check-semver-syntax.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions .github/workflows/gameci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 41e3034

Please sign in to comment.