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
135 changes: 135 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Auto Release

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: write

jobs:
create-release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Validate tag format
id: validate
run: |
TAG_NAME="${{ github.ref_name }}"
echo "Tag name: $TAG_NAME"

# Verify tag matches semver pattern
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ ERROR: Tag $TAG_NAME does not match semantic versioning pattern"
echo "Expected format: vX.Y.Z (e.g., v1.2.3)"
exit 1
fi

VERSION="${TAG_NAME#v}"
echo "Version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Check if release already exists
id: check_release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="${{ github.ref_name }}"

# Check if release already exists
if gh release view "$TAG_NAME" >/dev/null 2>&1; then
echo "❌ ERROR: Release for tag $TAG_NAME already exists!"
echo "If you want to recreate the release, delete it first:"
echo " gh release delete $TAG_NAME"
exit 1
fi

echo "✅ No existing release found for $TAG_NAME"

- name: Generate release notes
id: release_notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="${{ github.ref_name }}"
VERSION="${{ steps.validate.outputs.version }}"

# Get the previous tag
PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -2 | tail -1)

if [ -z "$PREV_TAG" ]; then
echo "No previous release found, this is the first release"
PREV_TAG=$(git rev-list --max-parents=0 HEAD)
fi

echo "Generating release notes from $PREV_TAG to $TAG_NAME"

# Get list of merged PRs between tags
echo "Fetching merged PRs..."
PR_LIST=""

# Get merge commits between previous tag and current tag
MERGE_COMMITS=$(git log ${PREV_TAG}..${TAG_NAME} --merges --pretty=format:"%H %s" | grep "Merge pull request #")

if [ -n "$MERGE_COMMITS" ]; then
while IFS= read -r commit_line; do
# Extract PR number from commit message (format: "Merge pull request #123 from ...")
PR_NUMBER=$(echo "$commit_line" | sed -n 's/.*Merge pull request #\([0-9]*\).*/\1/p')

if [ -n "$PR_NUMBER" ]; then
# Fetch PR details from GitHub API
PR_DATA=$(gh pr view "$PR_NUMBER" --json title,author --jq '{title: .title, author: .author.login}')
PR_TITLE=$(echo "$PR_DATA" | jq -r '.title')
PR_AUTHOR=$(echo "$PR_DATA" | jq -r '.author')

# Add to PR list
PR_LIST="${PR_LIST}- ${PR_TITLE} by @${PR_AUTHOR} in [#${PR_NUMBER}](https://github.com/${{ github.repository }}/pull/${PR_NUMBER})"$'\n'
fi
done <<< "$MERGE_COMMITS"
fi

# Generate basic release notes
cat > release_notes.md << EOFNOTES
## Release $VERSION

### What's Changed

EOFNOTES

# Add PR list if available
if [ -n "$PR_LIST" ]; then
echo "$PR_LIST" >> release_notes.md
echo "" >> release_notes.md
else
echo "No merged pull requests found in this release." >> release_notes.md
echo "" >> release_notes.md
fi

# Add full changelog link
cat >> release_notes.md << EOFNOTES
**Full Changelog**: [${PREV_TAG}...${TAG_NAME}](https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${TAG_NAME})

EOFNOTES

echo "release_notes_file=release_notes.md" >> $GITHUB_OUTPUT

- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.PAT_RELEASE_ENGINEER }}
run: |
TAG_NAME="${{ github.ref_name }}"
VERSION="${{ steps.validate.outputs.version }}"

gh release create "$TAG_NAME" \
--title "$TAG_NAME" \
--notes-file "${{ steps.release_notes.outputs.release_notes_file }}" \
--draft=false \
--prerelease=false

echo "✅ Successfully created release $TAG_NAME"
echo "The release workflow will now be triggered to build and publish Lambda Extension layers."
118 changes: 118 additions & 0 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Auto Tag on Version Bump

on:
pull_request:
types: [closed]
branches:
- main

jobs:
auto-tag:
# Only run if PR was merged (not just closed)
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check if PR is a version bump
id: check
run: |
PR_BRANCH="${{ github.event.pull_request.head.ref }}"
echo "PR branch: $PR_BRANCH"

# Check if branch matches pattern re/bump-for-*
if [[ "$PR_BRANCH" =~ ^re/bump-for-(.+)$ ]]; then
VERSION="${BASH_REMATCH[1]}"
echo "This is a version bump PR for version: $VERSION"
echo "is_version_bump=true" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
echo "This is not a version bump PR"
echo "is_version_bump=false" >> $GITHUB_OUTPUT
fi

- name: Check for no-auto-tag label
id: check_label
if: steps.check.outputs.is_version_bump == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"

# Get PR labels
LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name')

if echo "$LABELS" | grep -q "no-auto-tag"; then
echo "PR has 'no-auto-tag' label - skipping automatic tagging"
echo "skip_tag=true" >> $GITHUB_OUTPUT
else
echo "PR does not have 'no-auto-tag' label - will create tag"
echo "skip_tag=false" >> $GITHUB_OUTPUT
fi

- name: Check if tag already exists
if: steps.check.outputs.is_version_bump == 'true' && steps.check_label.outputs.skip_tag == 'false'
run: |
TAG_NAME="v${{ steps.check.outputs.version }}"
echo "Checking if tag $TAG_NAME already exists..."

# Fetch all tags from remote
git fetch --tags

# Check if tag exists locally or remotely
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "❌ ERROR: Tag $TAG_NAME already exists!"
echo "This usually means:"
echo " 1. A release for this version was already created"
echo " 2. The version in Cargo.toml was not bumped correctly"
echo ""
echo "To fix this:"
echo " - If the tag is incorrect, delete it: git push --delete origin $TAG_NAME"
echo " - If the version is wrong, create a new version bump PR with the correct version"
exit 1
fi

echo "✅ Tag $TAG_NAME does not exist, safe to create"

- name: Configure git
if: steps.check.outputs.is_version_bump == 'true' && steps.check_label.outputs.skip_tag == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Clear git credentials
if: steps.check.outputs.is_version_bump == 'true' && steps.check_label.outputs.skip_tag == 'false'
run: |
git config --unset-all http.https://github.com/.extraheader || true
git config --global --unset-all credential.helper || true
git config --local --unset-all credential.helper || true

- name: Create and push tag
if: steps.check.outputs.is_version_bump == 'true' && steps.check_label.outputs.skip_tag == 'false'
env:
GH_TOKEN: ${{ secrets.PAT_RELEASE_ENGINEER }}
run: |
TAG_NAME="v${{ steps.check.outputs.version }}"
echo "Creating tag: $TAG_NAME"

# Create annotated tag
git tag -a "$TAG_NAME" -m "Release $TAG_NAME"

# Push tag
git push "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git" "$TAG_NAME"

echo "✅ Successfully created and pushed tag $TAG_NAME"
echo "This will trigger the release workflow."

- name: Skip tagging notification
if: steps.check.outputs.is_version_bump == 'true' && steps.check_label.outputs.skip_tag == 'true'
run: |
echo "⏭️ Skipping automatic tagging due to 'no-auto-tag' label"
echo "To create a release manually, run:"
echo " git tag v${{ steps.check.outputs.version }}"
echo " git push origin v${{ steps.check.outputs.version }}"
114 changes: 114 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Bump Version

on:
workflow_dispatch:
inputs:
bump_type:
description: "Version bump type"
required: true
default: "patch"
type: choice
options:
- patch
- minor
- major

env:
CARGO_TERM_COLOR: always

jobs:
bump-version:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""

- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler

- name: Read current version and calculate new version
id: version
run: |
# Read current version from Cargo.toml
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "Current version: $CURRENT_VERSION"

# Split version into parts
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"

# Bump version based on input
case "${{ github.event.inputs.bump_type }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac

NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "New version: $NEW_VERSION"

echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "new=$NEW_VERSION" >> $GITHUB_OUTPUT

- name: Create branch
run: |
BRANCH_NAME="re/bump-for-${{ steps.version.outputs.new }}"
echo "Creating branch: $BRANCH_NAME"
git checkout -b "$BRANCH_NAME"
echo "branch=$BRANCH_NAME" >> $GITHUB_ENV

- name: Update Cargo.toml version
run: |
sed -i 's/^version = ".*"/version = "${{ steps.version.outputs.new }}"/' Cargo.toml
echo "Updated Cargo.toml to version ${{ steps.version.outputs.new }}"

- name: Run cargo check to update Cargo.lock
run: cargo check

- name: Commit and push changes
run: |
git add Cargo.toml Cargo.lock
git commit -m "Bump version to ${{ steps.version.outputs.new }}"
git push origin "${{ env.branch }}"

- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.PAT_RELEASE_ENGINEER }}
run: |
gh pr create \
--title "Release: Bump version to ${{ steps.version.outputs.new }}" \
--assignee "${{ github.actor }}" \
--body "This PR bumps the version from ${{ steps.version.outputs.current }} to ${{ steps.version.outputs.new }}.

**Bump type:** ${{ github.event.inputs.bump_type }}

After merging this PR, a tag \`v${{ steps.version.outputs.new }}\` will be automatically created and pushed, which will trigger the release workflow.

If you want to prevent automatic tagging, add the \`no-auto-tag\` label to this PR before merging." \
--base main \
--head "${{ env.branch }}"
Loading