Skip to content

skduncan is creating a Release Candidate πŸš€ #104

skduncan is creating a Release Candidate πŸš€

skduncan is creating a Release Candidate πŸš€ #104

name: Release Candidate
run-name: ${{ github.actor }} is creating a Release Candidate πŸš€
on:
push:
branches:
- master
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number'
required: true
pull_request:
types: [labeled]
jobs:
Creating-Release-Candidate:
# Only run release creation on master push or workflow_dispatch
# if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./playbook
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
steps:
- uses: actions/checkout@v3
- name: 'Enable registry auth'
shell: bash
run: |
echo "//registry.npmjs.org/:_authToken="$(echo -n '${{ secrets.NPM_TOKEN }}')"" >> ~/.npmrc
echo "//npm.powerapp.cloud/:_auth="$(echo -n 'gh-actions:${{ secrets.POWERHOME_NPM_REGISTRY_PASSWORD }}' | base64)"" >> ~/.npmrc
echo "//npm.powerapp.cloud/:always-auth = true" >> .npmrc
- uses: actions/setup-node@v4
with:
node-version: 20.11.0
- name: Ruby Setup
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Python Setup
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Set Git Config
run: |
git config --local user.name "${{ github.actor }}"
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
- name: Get Semver Label
id: get-label
run: |
set -x # Enable debug mode
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
PR_NUMBER="${{ github.event.inputs.pr_number }}"
echo "Using manually provided PR number: $PR_NUMBER"
else
echo "Analyzing commit for PR number..."
# Print full commit message for debugging
echo "Full commit message:"
git log -1 --pretty=%B
# Pattern 1: Merge pull request #X from ...
echo "Trying Pattern 1: Standard merge commit format (Merge pull request #X from ...)"
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP "Merge pull request #\K\d+" || true)
if [ ! -z "$PR_NUMBER" ]; then
echo "βœ… Pattern 1 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 1 did not find PR number"
fi
# Pattern 2: #X from ...
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 2: Simple PR reference (#X)"
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP "#\K\d+" || true)
if [ ! -z "$PR_NUMBER" ]; then
echo "βœ… Pattern 2 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 2 did not find PR number"
fi
fi
# Pattern 3: GitHub event payload
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 3: GitHub event payload"
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")
if [ ! -z "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
echo "βœ… Pattern 3 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 3 did not find PR number"
fi
fi
# Pattern 4: Commit message title
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 4: Commit message title"
PR_NUMBER=$(git log -1 --pretty=%s | grep -oP "#\K\d+" || true)
if [ ! -z "$PR_NUMBER" ]; then
echo "βœ… Pattern 4 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 4 did not find PR number"
fi
fi
# Pattern 5: GitHub API
if [ -z "$PR_NUMBER" ]; then
echo "Trying Pattern 5: GitHub API for commit"
COMMIT_SHA=$(git rev-parse HEAD)
echo "Checking commit SHA: $COMMIT_SHA"
PR_NUMBER=$(gh api repos/${{ github.repository }}/commits/$COMMIT_SHA/pulls --jq '.[0].number' || true)
if [ ! -z "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
echo "βœ… Pattern 5 successfully found PR number: $PR_NUMBER"
else
echo "❌ Pattern 5 did not find PR number"
fi
fi
echo "Final PR number extraction result: $PR_NUMBER"
fi
if [ -z "$PR_NUMBER" ]; then
echo "β›” Error: Could not determine PR number from any pattern"
echo "GitHub event name: ${{ github.event_name }}"
echo "GitHub event path content:"
cat "$GITHUB_EVENT_PATH"
exit 1
fi
echo "Fetching labels for PR #$PR_NUMBER..."
LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels[].name' || echo "Failed to fetch labels")
echo "Found labels: $LABELS"
if [ -z "$LABELS" ]; then
echo "β›” Error: Failed to fetch PR labels"
exit 1
fi
SEMVER_LABEL=$(echo "$LABELS" | grep -iE '^(major|minor|patch)$' || true)
echo "Found Semver labels: $SEMVER_LABEL"
if [ -z "$SEMVER_LABEL" ]; then
echo "β›” Error: No valid Semver label (major, minor, patch) found on PR #$PR_NUMBER."
exit 1
fi
LABEL_COUNT=$(echo "$SEMVER_LABEL" | wc -l)
echo "Number of Semver labels found: $LABEL_COUNT"
if [ "$LABEL_COUNT" -ne 1 ]; then
echo "β›” Error: Expected exactly one Semver label, found $LABEL_COUNT on PR #$PR_NUMBER."
exit 1
fi
echo "SEMVER_LABEL=$SEMVER_LABEL" >> $GITHUB_ENV
echo "βœ… Successfully found Semver label: $SEMVER_LABEL"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Grab Current Version and Set New RC Version
id: set-version
run: |
current_npm_version=$(node -pe "require('./package.json').version")
if [[ $current_npm_version == *"-rc."* ]]; then
new_npm_version=$(yarn version --prerelease --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
else
case ${{ env.SEMVER_LABEL }} in
Major)
new_npm_version=$(yarn version --premajor --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
;;
Minor)
new_npm_version=$(yarn version --preminor --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
;;
Patch)
new_npm_version=$(yarn version --prepatch --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
;;
*)
echo "Error: Invalid Semver label: ${{ env.SEMVER_LABEL }}"
exit 1
;;
esac
fi
new_npm_version=${new_npm_version#v}
new_ruby_version=$(echo $new_npm_version | sed 's/-rc\./.pre.rc./')
echo "new_npm_version=${new_npm_version}" >> $GITHUB_ENV
echo "new_ruby_version=${new_ruby_version}" >> $GITHUB_ENV
- name: Check if version exists and increment if necessary
run: |
max_attempts=100
attempt=0
current_version="${{ env.new_npm_version }}"
while [ $attempt -lt $max_attempts ]; do
if npm view playbook-ui@$current_version version &>/dev/null; then
echo "Version $current_version already exists. Incrementing..."
current_version=$(yarn version --prerelease --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
current_version=${current_version#v}
else
echo "Version $current_version is available."
break
fi
attempt=$((attempt+1))
done
if [ $attempt -eq $max_attempts ]; then
echo "Error: Maximum attempts reached. Unable to find an available version."
exit 1
fi
echo "new_npm_version=${current_version}" >> $GITHUB_ENV
new_ruby_version=$(echo $current_version | sed 's/-rc\./.pre.rc./')
echo "new_ruby_version=${new_ruby_version}" >> $GITHUB_ENV