From 41f9e1f4387ba5cca30e7932e2fde71891fb5f83 Mon Sep 17 00:00:00 2001 From: Ricky Heijnen Date: Sat, 27 Sep 2025 22:13:43 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Add=20GitHub=20Action=20for=20Re?= =?UTF-8?q?lease?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9c90c4a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,96 @@ +name: Tag Release + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: write # Needed for tags & releases + +concurrency: + group: tag-release-${{ github.ref }} + cancel-in-progress: false + +jobs: + tag-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Sync & prune tags + run: | + git fetch --tags --force --prune + + - name: Determine version from composer.json + id: version + run: | + VERSION=$(jq -r '.version // empty' composer.json) + if [ -z "$VERSION" ]; then + echo "composer.json does not have a 'version' field"; exit 1 + fi + + # prefix with 'v' if it's not already + if [[ "$VERSION" =~ ^v ]]; then + TAG="$VERSION" + else + TAG="v$VERSION" + fi + + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "Resolved tag: $TAG" + + - name: Check if tag exists on origin + id: check_tag + run: | + TAG="${{ steps.version.outputs.tag }}" + if git ls-remote --tags origin | grep -q "refs/tags/${TAG}$"; then + echo "exists=true" >> "$GITHUB_OUTPUT" + echo "Tag ${TAG} already exists on origin" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + echo "Tag ${TAG} does not exist on origin" + fi + + - name: Create and push tag + if: steps.check_tag.outputs.exists == 'false' + run: | + TAG="${{ steps.version.outputs.tag }}" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git config --global user.name "github-actions[bot]" + git tag -a "${TAG}" -m "Version ${TAG}" + git push origin "refs/tags/${TAG}" + + - name: Check if release exists + id: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + HTTP_STATUS=$(curl -sS -o /dev/null -w '%{http_code}' \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.version.outputs.tag }}") + if [ "$HTTP_STATUS" = "200" ]; then + echo "exists=true" >> "$GITHUB_OUTPUT" + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: Create GitHub Release (autogenerated notes) + if: steps.release.outputs.exists == 'false' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.version.outputs.tag }} + name: Version ${{ steps.version.outputs.tag }} + generate_release_notes: true + allow_updates: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}