From 8188654537a6d561a07c2b930a1eebe4464750b1 Mon Sep 17 00:00:00 2001 From: Sam Duncan Date: Thu, 17 Oct 2024 23:52:34 -0500 Subject: [PATCH] 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