diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 0000000..a4b6deb --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,63 @@ +name: Create Release + +on: + workflow_dispatch: + inputs: + version: + description: "Release version (e.g., 1.2.3, without the 'v' prefix)" + required: true + type: string + +permissions: + contents: write + +jobs: + create-release: + name: Create Release Tag + runs-on: ubuntu-latest + steps: + - name: Validate version format + env: + VERSION: ${{ inputs.version }} + run: | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then + echo "::error::Invalid version format '$VERSION'. Use X.X.X (e.g., 1.2.3)" + exit 1 + fi + + - name: Check out code + uses: actions/checkout@v5 + + - name: Check tag does not already exist + env: + VERSION: ${{ inputs.version }} + run: | + if git ls-remote --tags origin "refs/tags/v${VERSION}" | grep -q .; then + echo "::error::Tag v${VERSION} already exists" + exit 1 + fi + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Run tests + run: go test -race ./... + + - name: Update manifest.json version + env: + VERSION: ${{ inputs.version }} + run: | + jq --arg v "$VERSION" '.version = $v' manifest.json > manifest.tmp && mv manifest.tmp manifest.json + + - name: Commit, tag, and push + env: + VERSION: ${{ inputs.version }} + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add manifest.json + git commit --allow-empty -m "Release v${VERSION}" + git tag "v${VERSION}" + git push origin main "v${VERSION}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 254cb09..d53f4d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,6 +16,15 @@ jobs: - name: Check out code uses: actions/checkout@v5 + - name: Verify manifest version matches tag + run: | + TAG_VERSION="${GITHUB_REF_NAME#v}" + MANIFEST_VERSION=$(jq -r .version manifest.json) + if [ "$TAG_VERSION" != "$MANIFEST_VERSION" ]; then + echo "::error::Tag version ($TAG_VERSION) does not match manifest.json version ($MANIFEST_VERSION)" + exit 1 + fi + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/Makefile b/Makefile index db8a4cd..2a74ccb 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +SHELL := /usr/bin/env bash .PHONY: test build package clean PLUGIN_NAME := discord-rich-presence @@ -15,10 +16,8 @@ package: build clean: rm -f $(WASM_FILE) $(PLUGIN_NAME).ndp -release: test +release: @if [[ ! "${V}" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$$ ]]; then echo "Usage: make release V=X.X.X"; exit 1; fi - go mod tidy - @if [ -n "`git status -s`" ]; then echo "\n\nThere are pending changes. Please commit or stash first"; exit 1; fi - git tag v${V} - git push origin v${V} --no-verify + gh workflow run create-release.yml -f version=${V} + @echo "Release v${V} workflow triggered. Check progress: gh run list --workflow=create-release.yml" .PHONY: release