Deploy to Godot #6
This file contains hidden or 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: Deploy to Godot | |
| on: | |
| issues: | |
| types: [opened, labeled] | |
| jobs: | |
| deploy: | |
| name: Release Godot addon ZIP | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.issue.title == 'Deploy to Godot' && | |
| contains(github.event.issue.labels.*.name, 'CI') | |
| permissions: | |
| contents: write | |
| issues: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Read version from plugin.cfg | |
| id: version | |
| run: | | |
| VERSION=$(grep '^version=' godot/addons/qti_neon/plugin.cfg | cut -d'"' -f2) | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Build addon ZIP | |
| run: | | |
| mkdir -p _addon_pkg/addons | |
| cp -r godot/addons/qti_neon _addon_pkg/addons/qti_neon | |
| cd _addon_pkg | |
| zip -r ../qti-neon-${{ steps.version.outputs.version }}.zip addons/ | |
| cd .. | |
| rm -rf _addon_pkg | |
| - name: Create GitHub Release | |
| id: release | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const version = '${{ steps.version.outputs.version }}'; | |
| const tag = `godot-v${version}`; | |
| const zipName = `qti-neon-${version}.zip`; | |
| let release; | |
| try { | |
| release = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag, | |
| }); | |
| for (const asset of release.data.assets) { | |
| await github.rest.repos.deleteReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| asset_id: asset.id, | |
| }); | |
| } | |
| } catch { | |
| release = await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: tag, | |
| name: `QTI Neon (Godot) v${version}`, | |
| body: `Godot addon ZIP for qti_neon v${version}.\n\nInstall by extracting into your project root so that \`addons/qti_neon/\` is at the top level.`, | |
| draft: false, | |
| prerelease: false, | |
| }); | |
| } | |
| const zipData = fs.readFileSync(zipName); | |
| await github.rest.repos.uploadReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release.data.id, | |
| name: zipName, | |
| data: zipData, | |
| }); | |
| core.setOutput('release_url', release.data.html_url); | |
| - name: Comment on issue with result | |
| if: always() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const success = '${{ job.status }}' === 'success'; | |
| const version = '${{ steps.version.outputs.version }}'; | |
| const releaseUrl = '${{ steps.release.outputs.release_url }}'; | |
| const body = success | |
| ? `Release created for \`qti_neon\` v${version}. Download the ZIP from [the release](${releaseUrl}) and submit it to the Asset Library.` | |
| : `Deployment failed. Check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.`; | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body | |
| }); |