diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7850162..591cc65 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,18 +23,103 @@ on: description: "GitHub Token. Used to authenticate with GitHub at build step. This will overwrite the use of the default GitHub token." outputs: version: - description: "The version of the release. Will be null if no release was made." - value: ${{ jobs.release.outputs.version }} + description: "The version of the release. Will be empty if no release was made." + value: ${{ jobs.semantic-release.outputs.version }} jobs: - release: + semantic-release: + name: Semantic release + runs-on: ubuntu-latest + environment: ${{ inputs.ENVIRONMENT || '' }} permissions: contents: write packages: write id-token: write - name: Release - if: github.repository == ( inputs.repository || 'ctfpilot/ci') - uses: the0mikkel/ci/.github/workflows/semver-release-standalone.yml@v1.4.1 - secrets: inherit - with: - ENVIRONMENT: ${{ inputs.ENVIRONMENT }} + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: "lts/*" + - name: Install dependencies + run: npm install semantic-release @semantic-release/exec @semantic-release/commit-analyzer @semantic-release/git @semantic-release/github @semantic-release/release-notes-generator conventional-changelog-conventionalcommits -D + - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies + run: npm audit signatures + - name: Detect if configuration file is available for semantic-release + id: check-config + run: | + if [ -f .releaserc.json ] || [ -f .releaserc ] || [ -f release.config.js ]; then + echo "config_exists=true" >> $GITHUB_OUTPUT + else + echo "config_exists=false" >> $GITHUB_OUTPUT + fi + - name: Set default configuration file for semantic-release + if: steps.check-config.outputs.config_exists == 'false' + run: | + cat << 'EOF' > .releaserc.json + { + "branches": [ + "main", + { + "name": "develop", + "prerelease": "r" + } + ], + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/github", + { + "successComment": false + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "echo ${nextRelease.version} > version.txt", + "publishCmd": "echo 'Published version ${nextRelease.version}'" + } + ], + [ + "@semantic-release/git", + { + "assets": [], + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ] + ] + } + EOF + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_GH_TOKEN || secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.RELEASE_GH_TOKEN || secrets.GITHUB_TOKEN }} + run: | + npx semantic-release 2>&1 | tee semantic-release.log + status=${PIPESTATUS[0]} + exit $status + - name: Archive release log + uses: actions/upload-artifact@v5 + with: + name: semantic-release.log + path: semantic-release.log + - name: Get version + id: version + run: echo version=$(grep -oP "next release version is \K.*" semantic-release.log || echo "") >> $GITHUB_OUTPUT