nidaqg is creating an Alpha Version or RC 🚀 #18683
This file contains hidden or 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: Alpha Version | |
| run-name: ${{ github.actor }} is creating an Alpha Version or RC 🚀 | |
| on: | |
| pull_request: | |
| types: [ labeled ] # Trigger on labeling a PR | |
| push: | |
| branches: | |
| - master # Trigger on push to master (for RC) | |
| jobs: | |
| Creating-Alpha-Version: | |
| if: github.event.label.name == 'alpha' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| defaults: | |
| run: | |
| working-directory: ./playbook | |
| env: | |
| # Set an environment variable for the branch name | |
| BRANCH_NAME: ${{ github.head_ref }} | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: 'Enable registry auth' | |
| shell: bash | |
| run: | | |
| 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: 22.15.1 | |
| - name: Use npm 11.6.2 | |
| run: npm i -g npm@11.6.2 | |
| - 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: Grab Current Version | |
| run: | | |
| playbook_npm_version=$(node -pe "require('./package.json').version") | |
| echo "playbook_npm_version=${playbook_npm_version}" >> $GITHUB_ENV | |
| playbook_ruby_version=$(ruby -r ./lib/playbook/version.rb -e "puts Playbook::VERSION") | |
| echo "playbook_ruby_version=${playbook_ruby_version}" >> $GITHUB_ENV | |
| - name: Set New Alpha Version | |
| id: grab-package-version | |
| run: | | |
| formatted_branch=$(echo "${{ env.BRANCH_NAME }}" | tr -cd '[:alnum:]') | |
| npm_alpha_version="${{ env.playbook_npm_version }}-alpha.${formatted_branch}${{ github.run_number }}" | |
| ruby_alpha_version="${{ env.playbook_ruby_version }}.pre.alpha.${formatted_branch}${{ github.run_number }}" | |
| echo "new_npm_alpha_version=${npm_alpha_version}" >> $GITHUB_ENV | |
| echo "new_ruby_alpha_version=${ruby_alpha_version}" >> $GITHUB_ENV | |
| - name: Update Version.rb | |
| id: update-version-rb | |
| run: | | |
| gem install bundler | |
| bundle | |
| bin/rails pb_release:action[${{env.new_ruby_alpha_version}}] | |
| - name: Version Up, Distribute and Publish (NPM) | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| run: | | |
| yarn install | |
| yarn version --new-version ${{ env.new_npm_alpha_version }} | |
| bundle | |
| yarn release | |
| npm pack | |
| npm publish --registry https://registry.npmjs.org playbook-ui-${{ env.new_npm_alpha_version }}.tgz --tag alpha | |
| - name: Configure RubyGems Credentials | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| uses: rubygems/configure-rubygems-credentials@v2.1.0 | |
| - name: Version Up, Distribute and Publish (RubyGems) | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| run: | | |
| bin/build_gem | |
| echo "${{ env.new_ruby_alpha_version }}" | |
| gem push playbook_ui-${{ env.new_ruby_alpha_version }}.gem --host https://rubygems.org/ | |
| - name: Leave PR comment | |
| env: | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| RUBY_GEM_VERSION: ${{ env.new_ruby_alpha_version }} | |
| RUBY_GEM_LINK: https://rubygems.org/gems/playbook_ui/versions/${{env.new_ruby_alpha_version}} | |
| NPM_VERSION: ${{ env.new_npm_alpha_version }} | |
| NPM_LINK: https://www.npmjs.com/package/playbook-ui/v/${{env.new_npm_alpha_version}} | |
| run: | | |
| curl -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | |
| -X POST \ | |
| -d '{"body": "🎉 Congratulations on creating an Alpha Version! \n\n Your Alpha for Ruby Gems is [${{env.RUBY_GEM_VERSION}}](${{env.RUBY_GEM_LINK}}) \n\n Your Alpha for NPM is [${{env.NPM_VERSION}}](${{env.NPM_LINK}}) "}' \ | |
| "https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" | |
| Creating-Release-Candidate: | |
| if: github.event_name == 'push' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write # OIDC for npm publish | |
| contents: write # REQUIRED for gh release create | |
| issues: write | |
| pull-requests: write | |
| defaults: | |
| run: | |
| working-directory: ./playbook | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: 'Enable registry auth' | |
| shell: bash | |
| run: | | |
| 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: 22.15.1 | |
| - name: Use npm 11.6.2 | |
| run: npm i -g npm@11.6.2 | |
| - 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 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| PR_NUMBER=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| "https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \ | |
| | jq '.[0].number') | |
| echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
| if [ ! -z "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then | |
| echo "✅ Successfully found PR number: $PR_NUMBER" | |
| else | |
| echo "❌ Unable to find PR number" | |
| 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 | |
| if echo "$LABELS" | grep -iq "Inactive RC"; then | |
| echo "⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process." | |
| echo "SKIP_REMAINING_STEPS=true" >> $GITHUB_ENV # Set flag to skip steps | |
| exit 0 # Exit the job early, skipping the rest of the workflow | |
| fi | |
| SEMVER_LABEL=$(echo "$LABELS" | grep -iE '^(major|minor|patch)$' || true) | |
| echo "Found Semver labels: $SEMVER_LABEL" | |
| if [ -z "$SEMVER_LABEL" ]; then | |
| echo "⏭️ No Semver label found on PR #$PR_NUMBER." | |
| echo "ℹ️ This is likely an automated PR. Treating as 'Inactive RC' and skipping the release candidate process." | |
| echo "SKIP_REMAINING_STEPS=true" >> $GITHUB_ENV # Set flag to skip steps | |
| exit 0 # Exit the job early, skipping the rest of the workflow | |
| 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" | |
| echo "SEMVER_LABEL=$SEMVER_LABEL" >> $GITHUB_ENV | |
| echo "Semver label found: $SEMVER_LABEL" | |
| - name: Grab Current Version and Set New RC Version | |
| id: set-version | |
| run: | | |
| if [ "${{ env.SKIP_REMAINING_STEPS }}" == "true" ]; then | |
| echo "⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process." | |
| exit 0 | |
| fi | |
| current_npm_version=$(node -pe "require('./package.json').version") | |
| 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 | |
| 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: | | |
| if [ "${{ env.SKIP_REMAINING_STEPS }}" == "true" ]; then | |
| echo "⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process." | |
| exit 0 | |
| fi | |
| 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 | |
| - name: Update Version.rb | |
| run: | | |
| if [ "${{ env.SKIP_REMAINING_STEPS }}" == "true" ]; then | |
| echo "⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process." | |
| exit 0 | |
| fi | |
| gem install bundler | |
| bundle | |
| bin/rails pb_release:action[${{env.new_ruby_version}}] | |
| - name: Distribute and Publish (NPM) | |
| run: | | |
| if [ "${{ env.SKIP_REMAINING_STEPS }}" == "true" ]; then | |
| echo "⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process." | |
| exit 0 | |
| fi | |
| yarn install | |
| bundle | |
| yarn release | |
| npm pack | |
| npm publish --registry https://registry.npmjs.org playbook-ui-${{ env.new_npm_version }}.tgz --tag rc | |
| - name: Configure RubyGems Credentials | |
| if: env.SKIP_REMAINING_STEPS != 'true' | |
| uses: rubygems/configure-rubygems-credentials@v2.1.0 | |
| - name: Distribute and Publish (RubyGems) | |
| run: | | |
| if [ "${{ env.SKIP_REMAINING_STEPS }}" == "true" ]; then | |
| echo "⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process." | |
| exit 0 | |
| fi | |
| bin/build_gem | |
| gem push playbook_ui-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ "${{ env.SKIP_REMAINING_STEPS }}" == "true" ]; then | |
| echo "⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process." | |
| exit 0 | |
| fi | |
| gh release create v${{ env.new_npm_version }} \ | |
| --title "Release Candidate v${{ env.new_npm_version }}" \ | |
| --notes "This is a release candidate version. Please test thoroughly before promoting to a stable release." \ | |
| --prerelease | |
| - name: Leave PR comment | |
| uses: actions/github-script@v7 | |
| env: | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| RUBY_GEM_VERSION: ${{ env.new_ruby_version }} | |
| RUBY_GEM_LINK: https://rubygems.org/gems/playbook_ui/versions/${{env.new_ruby_version}} | |
| NPM_VERSION: ${{ env.new_npm_version }} | |
| NPM_LINK: https://www.npmjs.com/package/playbook-ui/v/${{env.new_npm_version}} | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| if (process.env.SKIP_REMAINING_STEPS === 'true') { | |
| console.log("⏭️ PR has the 'Inactive RC' label. Skipping the release candidate process."); | |
| return; | |
| } | |
| const commitSha = context.payload.head_commit.id; | |
| const commitMessage = context.payload.head_commit.message; | |
| const commitAuthor = context.payload.head_commit.author.name; | |
| const commitUrl = context.payload.head_commit.url; | |
| console.log(`Commit message: ${commitMessage}`); | |
| console.log(`Commit author: ${commitAuthor}`); | |
| console.log(`Commit URL: ${commitUrl}`); | |
| // Get the PR related to this commit using octokit API | |
| const pullRequests = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: commitSha | |
| }); | |
| if (pullRequests.data.length > 0) { | |
| const pullRequestNumber = pullRequests.data[0].number; | |
| console.log(`Found pull request #${pullRequestNumber} for commit ${commitSha}`); | |
| // Add a comment to the pull request | |
| await github.rest.issues.createComment({ | |
| issue_number: pullRequestNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `You merged this pr to master branch: | |
| - Ruby Gem: [${{env.RUBY_GEM_VERSION}}](${{env.RUBY_GEM_LINK}}) | |
| - NPM: [${{env.NPM_VERSION}}](${{env.NPM_LINK}})` | |
| }); | |
| } else { | |
| console.log('No pull request found for this commit'); | |
| } |