From 8188654537a6d561a07c2b930a1eebe4464750b1 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Thu, 17 Oct 2024 23:52:34 -0500 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5e2cdfcdc4c424c2abb6b0646151fa92d7e852fd Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Wed, 23 Oct 2024 10:02:02 -0500 Subject: [PATCH 5/7] Updating actions based on results of testing --- .../github-actions-release-candidate.yml | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index c9fecdcee6..92667dc8b6 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -40,30 +40,46 @@ jobs: - 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." + 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 "❌ 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 - LABELS=$(gh pr view $PR_NUMBER --json labels -q '.labels[].name') - SEMVER_LABEL=$(echo "$LABELS" | grep -E '^(major|minor|patch)$') + 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." + 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." + 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 @@ -74,13 +90,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}') ;; *) From aa9c3976c13dc4e5e547e51688d1063f17708949 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Mon, 11 Nov 2024 10:15:50 -0600 Subject: [PATCH 6/7] Removing else condition --- .github/workflows/github-actions-release-candidate.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 92667dc8b6..5b6a9b26d9 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -87,8 +87,6 @@ jobs: 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}') From 982fb6c9c6a3d65849b9dd9f87e148ca94752751 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Mon, 11 Nov 2024 10:26:12 -0600 Subject: [PATCH 7/7] Removing if entirely --- .../github-actions-release-candidate.yml | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/github-actions-release-candidate.yml b/.github/workflows/github-actions-release-candidate.yml index 5b6a9b26d9..610a882eef 100644 --- a/.github/workflows/github-actions-release-candidate.yml +++ b/.github/workflows/github-actions-release-candidate.yml @@ -86,23 +86,21 @@ jobs: run: | current_npm_version=$(node -pe "require('./package.json').version") - if [[ $current_npm_version == *"-rc."* ]]; then - 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 + 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./')