From 8188654537a6d561a07c2b930a1eebe4464750b1 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Thu, 17 Oct 2024 23:52:34 -0500 Subject: [PATCH 01/11] Adding github action to check for semver labels --- .../workflows/github-actions-check-labels.yml | 35 +++++++++++++++++++ .../github-actions-release-candidate.yml | 12 +++---- 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/github-actions-check-labels.yml diff --git a/.github/workflows/github-actions-check-labels.yml b/.github/workflows/github-actions-check-labels.yml new file mode 100644 index 0000000000..e369390c95 --- /dev/null +++ b/.github/workflows/github-actions-check-labels.yml @@ -0,0 +1,35 @@ +name: Check Labels +run-name: ${{ github.actor }} is checking labels 🚀 +on: + pull_request: + types: [ labeled, unlabeled ] +jobs: + Checking-Labels: + runs-on: ubuntu-latest + steps: + - name: Check for Semver label + run: | + LABELS=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") + SEMVER_PATTERN="^(major|minor|patch)$" + + SEMVER_LABELS=$(echo "$LABELS" | grep -iE "$SEMVER_PATTERN" || true) + + # Check if SEMVER_LABELS is empty + if [ -z "$SEMVER_LABELS" ]; then + echo "Error: No Semver label found. Please add exactly one of: major, minor, patch (case-insensitive)" + exit 1 + fi + + SEMVER_LABEL_COUNT=$(echo "$SEMVER_LABELS" | wc -l) + + if [ "$SEMVER_LABEL_COUNT" -eq 0 ]; then + echo "Error: No Semver label found. Please add exactly one of: major, minor, patch (case-insensitive)" + exit 1 + elif [ "$SEMVER_LABEL_COUNT" -gt 1 ]; then + echo "Error: Multiple Semver labels found. Please ensure only one is present:" + echo "$SEMVER_LABELS" + exit 1 + else + NORMALIZED_LABEL=$(echo "$SEMVER_LABELS" | tr '[:upper:]' '[:lower:]') + echo "Valid Semver label found: $NORMALIZED_LABEL" + fi \ No newline at end of file diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 0df9bed6c3..725fa2e03c 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -30,8 +30,8 @@ jobs: with: bundler-cache: true - name: Python Setup - uses: actions/setup-python@v4 - with: + uses: actions/setup-python@v4 + with: python-version: '3.9' - name: Set Git Config run: | @@ -41,16 +41,16 @@ jobs: 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 new_npm_version=$(yarn version --preminor --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}') 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 @@ -146,4 +146,4 @@ jobs: }); } else { console.log('No pull request found for this commit'); - } + } \ No newline at end of file From 46563bff88445bb286c81180bc69d435fa096d37 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Mon, 21 Oct 2024 08:08:45 -0500 Subject: [PATCH 02/11] Updating github actions to update version based on attached Semver label --- .../github-actions-release-candidate.yml | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 725fa2e03c..c9fecdcee6 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -37,6 +37,34 @@ jobs: 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: | + PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '#\K\d+') + if [ -z "$PR_NUMBER" ]; then + echo "Error: No PR number found in commit message." + exit 1 + fi + + LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels[].name') + SEMVER_LABEL=$(echo "$LABELS" | grep -E '^(major|minor|patch)$') + + 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) + 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 "Semver label found: $SEMVER_LABEL" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Grab Current Version and Set New RC Version id: set-version run: | @@ -45,7 +73,21 @@ jobs: 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 - new_npm_version=$(yarn version --preminor --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}') + 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} @@ -53,6 +95,7 @@ jobs: 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 @@ -140,7 +183,7 @@ jobs: issue_number: pullRequestNumber, owner: context.repo.owner, repo: context.repo.repo, - body: `You merged this pr to master branch: + 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}})` }); From ba3c50adcca37b7c996f1f6fc286501d8c14620b Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Mon, 21 Oct 2024 08:48:54 -0500 Subject: [PATCH 03/11] Adding a log to check output of PR number pull --- .github/workflows/github-actions-check-labels.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/github-actions-check-labels.yml b/.github/workflows/github-actions-check-labels.yml index e369390c95..697e8d5d78 100644 --- a/.github/workflows/github-actions-check-labels.yml +++ b/.github/workflows/github-actions-check-labels.yml @@ -9,6 +9,8 @@ jobs: steps: - name: Check for Semver label run: | + PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '#\K\d+') + echo "Here is the PR Number: $PR_NUMBER" LABELS=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") SEMVER_PATTERN="^(major|minor|patch)$" From 9779eb1a6992a77de48eb451948c2b003e220efd Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Mon, 21 Oct 2024 08:58:51 -0500 Subject: [PATCH 04/11] Reverting --- .github/workflows/github-actions-check-labels.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/github-actions-check-labels.yml b/.github/workflows/github-actions-check-labels.yml index 697e8d5d78..e369390c95 100644 --- a/.github/workflows/github-actions-check-labels.yml +++ b/.github/workflows/github-actions-check-labels.yml @@ -9,8 +9,6 @@ jobs: steps: - name: Check for Semver label run: | - PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '#\K\d+') - echo "Here is the PR Number: $PR_NUMBER" LABELS=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH") SEMVER_PATTERN="^(major|minor|patch)$" From 8debc26dcf303d60ea5daeab342fba5595294196 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Tue, 22 Oct 2024 14:05:10 -0500 Subject: [PATCH 05/11] Modifying workflow to allow rc to run on label changes. Workflow can also manually run via Github UI. Also commenting out publish actions in rc in case for safety. --- .../github-actions-release-candidate.yml | 143 ++++++++++-------- 1 file changed, 76 insertions(+), 67 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index c9fecdcee6..71007bab95 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -4,9 +4,18 @@ 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: @@ -119,74 +128,74 @@ jobs: 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: | - gem install bundler - bundle - bin/rails pb_release:action[${{env.new_ruby_version}}] - - name: Distribute and Publish (NPM) - run: | - yarn install - bundle - yarn release - npm pack - npm publish --registry https://registry.npmjs.org playbook-ui-${{ env.new_npm_version }}.tgz --tag rc - - name: Distribute and Publish (RubyGems) - run: | - bin/build_gem - gem build lib/playbook_ui_docs.gemspec - rm -rf dist/playbook-doc.js dist/playbook-rails.js dist/app dist/pb_doc_helper.rb dist/menu.yml - gem push playbook_ui-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }} - gem push playbook_ui_docs-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }} - - name: Create GitHub Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - 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@v6 - 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: | - 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; + # - name: Update Version.rb + # run: | + # gem install bundler + # bundle + # bin/rails pb_release:action[${{env.new_ruby_version}}] + # - name: Distribute and Publish (NPM) + # run: | + # yarn install + # bundle + # yarn release + # npm pack + # npm publish --registry https://registry.npmjs.org playbook-ui-${{ env.new_npm_version }}.tgz --tag rc + # - name: Distribute and Publish (RubyGems) + # run: | + # bin/build_gem + # gem build lib/playbook_ui_docs.gemspec + # rm -rf dist/playbook-doc.js dist/playbook-rails.js dist/app dist/pb_doc_helper.rb dist/menu.yml + # gem push playbook_ui-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }} + # gem push playbook_ui_docs-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }} + # - name: Create GitHub Release + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # run: | + # 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@v6 + # 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: | + # 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}`); + # 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 - }); + # // 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}`); + # 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'); - } \ No newline at end of file + # // 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'); + # } \ No newline at end of file From f1a37494aca9aca111ffce051d4f87f1a39fccc5 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Tue, 22 Oct 2024 14:13:46 -0500 Subject: [PATCH 06/11] Commenting out if statement to try version update --- .github/workflows/github-actions-release-candidate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 71007bab95..3654761256 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -15,7 +15,7 @@ on: jobs: Creating-Release-Candidate: # Only run release creation on master push or workflow_dispatch - if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + # if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest defaults: run: From 85a429bcd7c854e03d48d2a29466fb54dc18540b Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Tue, 22 Oct 2024 14:25:25 -0500 Subject: [PATCH 07/11] Adding debugging to check errors in rc workflow --- .../github-actions-release-candidate.yml | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 3654761256..a9b9d72e2e 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -49,30 +49,57 @@ jobs: - name: Get Semver Label id: get-label run: | - PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '#\K\d+') + set -x # Enable debug mode to print commands as they execute + + echo "Event name: ${{ github.event_name }}" + + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + PR_NUMBER="${{ github.event.inputs.pr_number }}" + echo "Using provided PR number: $PR_NUMBER" + else + echo "Getting PR number from last commit message..." + git log -1 --pretty=%B + PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '#\K\d+' || true) + echo "Extracted PR number: $PR_NUMBER" + fi + if [ -z "$PR_NUMBER" ]; then - echo "Error: No PR number found in commit message." + echo "Error: No PR number found." exit 1 fi - - LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels[].name') - SEMVER_LABEL=$(echo "$LABELS" | grep -E '^(major|minor|patch)$') - + + echo "Fetching labels for PR #$PR_NUMBER..." + gh auth status + LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels[].name' || echo "Failed to fetch labels") + echo "Found labels: $LABELS" + + if [ "$?" -ne 0 ]; then + echo "Error: Failed to fetch PR labels" + exit 1 + fi + + echo "Filtering for Semver labels..." + SEMVER_LABEL=$(echo "$LABELS" | grep -E '^(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 "Semver label found: $SEMVER_LABEL" + echo "Successfully found Semver label: $SEMVER_LABEL" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Adding explicit GH_TOKEN for gh CLI - name: Grab Current Version and Set New RC Version id: set-version From e67ddd95ec4233ad7e6f89cae6189cf81c8d7bf7 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Tue, 22 Oct 2024 14:38:12 -0500 Subject: [PATCH 08/11] Adding different patterns for attempting to find PR number for testing --- .../github-actions-release-candidate.yml | 90 +++++++++++++++---- 1 file changed, 73 insertions(+), 17 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index a9b9d72e2e..497d41438e 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -49,41 +49,98 @@ jobs: - name: Get Semver Label id: get-label run: | - set -x # Enable debug mode to print commands as they execute - - echo "Event name: ${{ github.event_name }}" + set -x # Enable debug mode if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then PR_NUMBER="${{ github.event.inputs.pr_number }}" - echo "Using provided PR number: $PR_NUMBER" + echo "Using manually provided PR number: $PR_NUMBER" else - echo "Getting PR number from last commit message..." + echo "Analyzing commit for PR number..." + + # Print full commit message for debugging + echo "Full commit message:" git log -1 --pretty=%B - PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '#\K\d+' || true) - echo "Extracted PR number: $PR_NUMBER" + + # 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: No PR number found." + 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..." - gh auth status LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels[].name' || echo "Failed to fetch labels") echo "Found labels: $LABELS" - if [ "$?" -ne 0 ]; then - echo "Error: Failed to fetch PR labels" + if [ -z "$LABELS" ]; then + echo "⛔ Error: Failed to fetch PR labels" exit 1 fi - echo "Filtering for Semver labels..." SEMVER_LABEL=$(echo "$LABELS" | grep -E '^(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." + echo "⛔ Error: No valid Semver label (major, minor, patch) found on PR #$PR_NUMBER." exit 1 fi @@ -91,16 +148,15 @@ jobs: 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." + 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 "✅ Successfully found Semver label: $SEMVER_LABEL" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Adding explicit GH_TOKEN for gh CLI - + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Grab Current Version and Set New RC Version id: set-version run: | From 3d219256a3fcaf1039d7fc3780c85ed0480ac824 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Tue, 22 Oct 2024 14:49:02 -0500 Subject: [PATCH 09/11] Realized the label check is case sensitive. Changing that. --- .github/workflows/github-actions-release-candidate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 497d41438e..eb62979915 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -136,7 +136,7 @@ jobs: exit 1 fi - SEMVER_LABEL=$(echo "$LABELS" | grep -E '^(major|minor|patch)$' || true) + SEMVER_LABEL=$(echo "$LABELS" | grep -iE '^(major|minor|patch)$' || true) echo "Found Semver labels: $SEMVER_LABEL" if [ -z "$SEMVER_LABEL" ]; then From dcd01f7bebb76ffabcc15c54f3f02686f5301247 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Tue, 22 Oct 2024 15:05:14 -0500 Subject: [PATCH 10/11] Updating test based on error. Removing commented code for safety --- .../github-actions-release-candidate.yml | 77 +------------------ 1 file changed, 3 insertions(+), 74 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index eb62979915..75a231b2fa 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -166,13 +166,13 @@ jobs: 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) + Major) new_npm_version=$(yarn version --premajor --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}') ;; - minor) + Minor) new_npm_version=$(yarn version --preminor --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}') ;; - patch) + Patch) new_npm_version=$(yarn version --prepatch --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}') ;; *) @@ -211,74 +211,3 @@ jobs: 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: | - # gem install bundler - # bundle - # bin/rails pb_release:action[${{env.new_ruby_version}}] - # - name: Distribute and Publish (NPM) - # run: | - # yarn install - # bundle - # yarn release - # npm pack - # npm publish --registry https://registry.npmjs.org playbook-ui-${{ env.new_npm_version }}.tgz --tag rc - # - name: Distribute and Publish (RubyGems) - # run: | - # bin/build_gem - # gem build lib/playbook_ui_docs.gemspec - # rm -rf dist/playbook-doc.js dist/playbook-rails.js dist/app dist/pb_doc_helper.rb dist/menu.yml - # gem push playbook_ui-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }} - # gem push playbook_ui_docs-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }} - # - name: Create GitHub Release - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # run: | - # 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@v6 - # 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: | - # 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'); - # } \ No newline at end of file From 454e7e11d55aad473ea4774be6d5d154e0badb26 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Tue, 22 Oct 2024 17:04:21 -0500 Subject: [PATCH 11/11] Cleaning up Get Semver Label action --- .../github-actions-release-candidate.yml | 98 +++---------------- 1 file changed, 16 insertions(+), 82 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 75a231b2fa..6f5a90f9da 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -46,117 +46,51 @@ jobs: 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" + PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH" 2>/dev/null || echo "") + if [ ! -z "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then + echo "✅ Successfully found 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" + echo "❌ Unable to find 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" + + echo "SEMVER_LABEL=$SEMVER_LABEL" >> $GITHUB_ENV + echo "Semver label found: $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: |