Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/auto-release-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Auto Release PR

on:
push:
branches: [develop]
workflow_dispatch:

permissions:
contents: read
pull-requests: write

concurrency:
group: auto-release-pr
cancel-in-progress: false

jobs:
create-release-pr:
name: Create Release PR
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Fetch main branch
run: git fetch origin main

- name: Check for existing PR
id: check-pr
run: |
PR_COUNT=$(gh pr list --base main --head develop --state open --json number --jq 'length')
echo "pr_exists=$([[ $PR_COUNT -gt 0 ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "::notice::Open PRs from develop to main: $PR_COUNT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check for differences
id: check-diff
if: steps.check-pr.outputs.pr_exists == 'false'
run: |
DIFF_COUNT=$(git rev-list --count origin/main..origin/develop)
echo "has_changes=$([[ $DIFF_COUNT -gt 0 ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "commit_count=$DIFF_COUNT" >> $GITHUB_OUTPUT
echo "::notice::Commits ahead of main: $DIFF_COUNT"

- name: Create Release PR
if: steps.check-pr.outputs.pr_exists == 'false' && steps.check-diff.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_COUNT: ${{ steps.check-diff.outputs.commit_count }}
run: |
printf '%s\n' \
"## Automatic Release PR" \
"" \
"This PR was automatically created after changes were pushed to develop." \
"" \
"**Commits:** ${COMMIT_COUNT} new commit(s)" \
"" \
"### Checklist" \
"- [ ] Review all changes" \
"- [ ] Verify CI passes" \
"- [ ] Approve and merge when ready for production" \
> /tmp/pr-body.md

gh pr create \
--base main \
--head develop \
--title "Release: develop -> main" \
--body-file /tmp/pr-body.md
89 changes: 89 additions & 0 deletions .github/workflows/auto-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Auto Tag on Merge

on:
push:
branches: [main]

permissions:
contents: write

concurrency:
group: auto-tag
cancel-in-progress: false

jobs:
create-tag:
name: Create Release Tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Get latest tag
id: get-tag
run: |
LATEST_TAG=$(git tag -l --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)

if [ -z "$LATEST_TAG" ]; then
echo "No existing tags found, starting with v0.0.0"
LATEST_TAG="v0.0.0"
fi

echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "::notice::Latest tag: $LATEST_TAG"

- name: Calculate next version
id: next-version
run: |
LATEST_TAG="${{ steps.get-tag.outputs.latest_tag }}"

VERSION="${LATEST_TAG#v}"
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
PATCH=$(echo "$VERSION" | cut -d. -f3)

NEW_PATCH=$((PATCH + 1))
NEW_TAG="v${MAJOR}.${MINOR}.${NEW_PATCH}"

echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
echo "::notice::New tag: $NEW_TAG"

- name: Check if tag exists
id: check-tag
run: |
NEW_TAG="${{ steps.next-version.outputs.new_tag }}"
if git rev-parse "$NEW_TAG" >/dev/null 2>&1; then
echo "::error::Tag $NEW_TAG already exists!"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi

- name: Create tag and release
if: steps.check-tag.outputs.exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_TAG: ${{ steps.next-version.outputs.new_tag }}
PREV_TAG: ${{ steps.get-tag.outputs.latest_tag }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Go submodule convention: the module at /go/ needs a `go/vX.Y.Z`
# tag on the same commit, otherwise `go install` cannot resolve
# the package — see CONTRIBUTING.md "Releases".
GO_TAG="go/${NEW_TAG}"
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
git tag -a "$GO_TAG" -m "$GO_TAG: submodule tag matching $NEW_TAG"
git push origin "$NEW_TAG" "$GO_TAG"

if [ "$PREV_TAG" = "v0.0.0" ]; then
gh release create "$NEW_TAG" --title "$NEW_TAG" --generate-notes
else
gh release create "$NEW_TAG" --title "$NEW_TAG" --generate-notes --notes-start-tag "$PREV_TAG"
fi

echo "::notice::Created tags $NEW_TAG and $GO_TAG, plus release $NEW_TAG"
6 changes: 3 additions & 3 deletions .github/workflows/test.yml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: test
name: PR checks

on:
push:
branches: [main]
pull_request:
push:
branches: [develop, main]

permissions:
contents: read
Expand Down
Loading