ci: add auto-release-tagging workflow #109
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Release | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
tags: | |
- '**' | |
env: | |
packageName: "nadena.dev.ndmf" | |
jobs: | |
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/') | |
run: | | |
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 | |
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 | |
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/') | |
run: | | |
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: Set Environment Variables | |
run: | | |
echo "zipFile=${{ env.packageName }}-${{ steps.version.outputs.prop }}".zip >> $GITHUB_ENV | |
echo "unityPackage=${{ env.packageName }}-${{ steps.version.outputs.prop }}.unitypackage" >> $GITHUB_ENV | |
- name: Create Zip | |
uses: thedoctor0/zip-release@a24011d8d445e4da5935a7e73c1f98e22a439464 | |
with: | |
type: "zip" | |
directory: "." | |
filename: ".github/${{env.zipFile}}" # make the zip file two directories up, since we start two directories in above | |
exclusions: '.github .git* *~ .gitignore *.ps1*' | |
- name: Move zipfile | |
run: | | |
mv .github/${{env.zipFile}} ${{env.zipFile}} | |
- uses: actions/upload-artifact@v3 | |
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: 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 |