diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7749fc4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release + +on: + push: + tags: ['v*'] + workflow_dispatch: + inputs: + tag: + description: Release tag (defaults to v) + required: false + type: string + draft: + description: Publish the release as a draft + required: false + type: boolean + default: true + +permissions: + contents: write + +concurrency: + group: release-${{ github.ref }} + cancel-in-progress: false + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 22 + cache: npm + - name: Resolve release metadata + id: meta + env: + INPUT_TAG: ${{ inputs.tag }} + run: | + version="$(node -p "require('./package.json').version")" + tag="${INPUT_TAG:-v$version}" + if [ "$tag" != "v$version" ]; then + echo "Tag $tag does not match package.json version $version" >&2 + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "tag=$tag" >> "$GITHUB_OUTPUT" + - run: npm ci + - run: npm run legal -- --check + - run: npm test + - run: npm run package + - run: npm run check:package + - name: Extract release notes + env: + VERSION: ${{ steps.meta.outputs.version }} + run: | + node --input-type=module <<'EOF' + import { readFile, writeFile } from 'node:fs/promises'; + + const version = process.env.VERSION; + const changelog = await readFile('CHANGELOG.md', 'utf8'); + const section = changelog + .split(/^## /m) + .slice(1) + .find((entry) => entry.split(/\s/)[0] === version); + const notes = section ? section.slice(section.indexOf('\n') + 1).trim() : ''; + await writeFile( + 'release-notes.md', + notes ? `${notes}\n` : 'See CHANGELOG.md for details.\n', + ); + EOF + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.meta.outputs.tag }} + target_commitish: ${{ github.sha }} + name: Minecraft Workbench v${{ steps.meta.outputs.version }} + body_path: release-notes.md + files: '*.vsix' + fail_on_unmatched_files: true + draft: ${{ github.event_name != 'workflow_dispatch' || inputs.draft }} + prerelease: false