Skip to content

feat!: set up static site generation functionality for next-1.0.0 #60

feat!: set up static site generation functionality for next-1.0.0

feat!: set up static site generation functionality for next-1.0.0 #60

Workflow file for this run

name: Automated Release
on:
pull_request:
branches:
- main
- next
push:
branches:
- main
- next
permissions:
contents: write
actions: read
jobs:
check-commit:
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Check commit message
id: check
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if [[ $COMMIT_MESSAGE =~ ^feat!.* ]] || [[ $COMMIT_MESSAGE =~ ^feat:.* ]] || [[ $COMMIT_MESSAGE =~ ^fix:.* ]]; then
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "should_release=false" >> $GITHUB_OUTPUT
echo "No version bump needed (commit: $COMMIT_MESSAGE)"
fi
release:
needs: check-commit
if: needs.check-commit.outputs.should_release == 'true'
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Swift
uses: swift-actions/setup-swift@v2
with:
swift-version: "6.1"
- name: Cache SwiftPM dependencies
uses: actions/cache@v3
with:
path: .build
key: ${{ runner.os }}-swiftpm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-swiftpm-
- name: Resolve dependencies
run: swift package resolve
- name: Run tests
run: swift test
continue-on-error: false
- name: Setup GitHub CLI
run: |
brew install gh
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Bump version and create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
# Get the latest version tag (default to 0.0.0 if none)
LATEST_TAG=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1)
if [ -z "$LATEST_TAG" ]; then
CURRENT_VERSION="0.0.0"
else
CURRENT_VERSION="$LATEST_TAG"
fi
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
# Get last commit message
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
# Determine version bump
if [[ $COMMIT_MESSAGE =~ ^feat!.* ]]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [[ $COMMIT_MESSAGE =~ ^feat:.* ]]; then
MINOR=$((MINOR + 1))
PATCH=0
elif [[ $COMMIT_MESSAGE =~ ^fix:.* ]]; then
PATCH=$((PATCH + 1))
else
echo "No version bump needed (commit: $COMMIT_MESSAGE)"
exit 0
fi
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
git push origin next
git tag -a "$NEW_VERSION" -m "$NEW_VERSION"
git push origin "$NEW_VERSION"
# Generate release notes from commits since last tag
if [ -z "$LATEST_TAG" ]; then
RELEASE_NOTES=$(git log --pretty=format:"- %s")
else
RELEASE_NOTES=$(git log "$LATEST_TAG"..HEAD --pretty=format:"- %s")
fi
echo "Release notes:"
echo "$RELEASE_NOTES"
gh release create "$NEW_VERSION" \
--title "Pre-release $NEW_VERSION" \
--notes "$RELEASE_NOTES" \
--prerelease