Create Version and Tag #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Version and Tag | |
# If you change this name, don't forget to change the name in 'deploy.yml'! | |
on: | |
schedule: | |
- cron: '0 3 * * 1' # Every Monday at 3am UTC | |
workflow_dispatch: # For manual triggering | |
env: | |
JAVA_VERSION: '11' | |
NODE_VERSION: '16.x' | |
jobs: | |
check-release-needed: | |
name: Check if release is needed | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
fetch-depth: 0 # Need full history for tags | |
- name: Verify repository state | |
run: | | |
# Ensure we're on master | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
if [ "$current_branch" != "master" ]; then | |
echo "ERROR: Not on master branch! Current branch: $current_branch" | |
exit 1 | |
fi | |
# Ensure we have tags | |
if ! git tag | grep -q '^v'; then | |
echo "ERROR: No version tags found in repository!" | |
exit 1 | |
fi | |
# Get the latest commit | |
latest_commit=$(git rev-parse HEAD) | |
echo "Latest commit: $latest_commit" | |
# Get all tags on the latest commit | |
tags_on_commit=$(git tag --points-at $latest_commit) | |
echo "Tags on latest commit:" | |
echo "$tags_on_commit" | |
# Check for version tags | |
if echo "$tags_on_commit" | grep -q '^v'; then | |
echo "Latest commit already has a version tag. Details:" | |
echo "$tags_on_commit" | grep '^v' | |
echo "No new release needed." | |
exit 1 | |
fi | |
# Get the most recent version tag | |
previous_version=$(git tag --sort=-v:refname | grep '^v' | head -n1) | |
if [ -z "$previous_version" ]; then | |
echo "ERROR: Could not determine previous version!" | |
exit 1 | |
fi | |
echo "Previous version: $previous_version" | |
# Check what files changed since last release | |
echo "Changes since $previous_version:" | |
changes_all=$(git diff --name-only $previous_version HEAD) | |
echo "$changes_all" | |
# Check if only .github files changed | |
changes_non_github=$(echo "$changes_all" | grep -v '^\.github/') | |
if [ -z "$changes_non_github" ]; then | |
echo "Only .github files changed since $previous_version. No release needed." | |
exit 1 | |
fi | |
# Verify the previous release commit message | |
prev_release_commit=$(git rev-list -n 1 $previous_version) | |
prev_commit_msg=$(git log -1 --format=%B $prev_release_commit) | |
prev_version_number=${previous_version#v} # Remove 'v' prefix | |
expected_msg="Bump version to $prev_version_number" | |
if [ "$prev_commit_msg" != "$expected_msg" ]; then | |
echo "WARNING: Previous release commit message doesn't match expected format" | |
echo "Expected: $expected_msg" | |
echo "Found: $prev_commit_msg" | |
# Not failing here as this is just a warning | |
fi | |
# Verify previous release was made by the bot | |
prev_release_author=$(git log -1 --format='%ae' $prev_release_commit) | |
if ! echo "$prev_release_author" | grep -q "effekt-updater\[bot\]@users.noreply.github.com"; then | |
echo "WARNING: Previous release wasn't made by effekt-updater[bot]" | |
echo "Author: $prev_release_author" | |
# Not failing here as this is just a warning | |
fi | |
echo "All checks passed. Release is needed!" | |
run-tests: # redux of usual CI defined in `ci.yml` | |
name: Run tests | |
needs: [check-release-needed] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- name: Set up JDK ${{ env.JAVA_VERSION }} | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JAVA_VERSION }} | |
distribution: 'zulu' | |
cache: 'sbt' | |
- name: Setup SBT | |
uses: sbt/setup-sbt@v1 | |
- name: Set up NodeJS ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install Chez Scheme, LLVM & libuv | |
run: sudo apt-get install -y chezscheme llvm-15 libuv1-dev | |
- name: Run tests with retry | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 120 # NOTE: This needs _some_ value. As of writing this, 2 hours should be future-proof. :) | |
max_attempts: 3 | |
retry_on: error | |
command: sbt clean test | |
new_command_on_retry: sbt testQuick # should only rerun failed tests | |
set-version: | |
name: Bump Version | |
needs: [run-tests] | |
runs-on: ubuntu-latest | |
outputs: | |
new_version: ${{ steps.set-version.outputs.VERSION }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- name: Set up JDK ${{ env.JAVA_VERSION }} | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JAVA_VERSION }} | |
distribution: 'zulu' | |
cache: 'sbt' | |
- name: Setup SBT | |
uses: sbt/setup-sbt@v1 | |
- name: Bump Effekt version using sbt | |
id: set-version | |
run: | | |
full_output=$(sbt 'bumpMinorVersion' -error) | |
new_version=$(echo "$full_output" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | tail -n 1) | |
new_version=$(echo "$new_version" | xargs) | |
if [[ ! $new_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Error: Version bump failed. Invalid version number: '${new_version}'" | |
echo "Full output was:" | |
echo "$full_output" | |
exit 1 | |
fi | |
echo "VERSION=${new_version}" >> $GITHUB_OUTPUT | |
echo "Successfully set new version: ${new_version}" | |
- name: Update Effekt version in NPM and MVN via sbt | |
run: sbt updateVersions | |
- name: Upload updated files | |
uses: actions/upload-artifact@v3 | |
with: | |
name: updated-files | |
path: | | |
project/EffektVersion.scala | |
package.json | |
pom.xml | |
commit-and-push: | |
name: Commit and Push Changes | |
needs: [set-version] | |
runs-on: ubuntu-latest | |
steps: | |
# Login as a GitHub App in order to bypass rules about committing to `master` directly | |
- name: Get GitHub App token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ secrets.EFFEKT_UPDATER_GH_APP_ID }} | |
private-key: ${{ secrets.EFFEKT_UPDATER_GH_CREDENTIALS_TOKEN }} | |
- name: Checkout code with token | |
uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
token: ${{ steps.app-token.outputs.token }} | |
- name: Download updated files | |
uses: actions/download-artifact@v3 | |
with: | |
name: updated-files | |
- name: Get GitHub App User ID | |
id: get-user-id | |
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
- name: Commit and push changes | |
run: | | |
echo "Verifying token and auth status:" | |
gh auth status | |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' | |
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>' | |
git add project/EffektVersion.scala | |
git add package.json | |
git add pom.xml | |
git commit -m "Bump version to ${{ needs.set-version.outputs.new_version }}" | |
git push | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
- name: Create and push tag | |
run: | | |
git tag v${{ needs.set-version.outputs.new_version }} | |
git push origin v${{ needs.set-version.outputs.new_version }} | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} |