Skip to content

Commit

Permalink
feat(ci): πŸ”– add appropriate labels to PRs with failed checks (#2793)
Browse files Browse the repository at this point in the history
Signed-off-by: Okinea Dev <[email protected]>
Co-authored-by: Okinea Dev <[email protected]>
  • Loading branch information
PKief and Okinea Dev authored Jan 11, 2025
1 parent e90f90e commit 930dc09
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
24 changes: 24 additions & 0 deletions .github/scripts/update-status-label.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# Only for GitHub Actions
# Parameters: <pr_number> <status> <label>
# Example: ./update-status-label.sh 1234 failure "invalid-colors"

# Exit on error
set -e

pr_number="$1"
status="$2"
label="$3"

action="add-label" && [ "$status" == "success" ] && action="remove-label"

# Add or remove label
export GH_TOKEN="$GITHUB_TOKEN"
gh pr edit "$pr_number" --$action "$label"

[ "$action" == "add-label" ] && echo "βœ… Added \"$label\" label to PR #$pr_number"
[ "$action" == "remove-label" ] && echo "βœ… Removed \"$label\" label from PR #$pr_number"

# 0 = success
exit 0
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ on:

permissions:
contents: read
pull-requests: write
issues: write # Update issue labels

jobs:
build:
Expand All @@ -37,8 +39,6 @@ jobs:
steps:
- name: πŸ“₯ Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: πŸ”§ Setup Bun
uses: oven-sh/setup-bun@4bc047ad259df6fc24a6c9b0f9a0cb08cf17fbe5 # v2
Expand All @@ -49,6 +49,13 @@ jobs:
run: bun install --frozen-lockfile

- name: πŸš€ Test + Build
id: build
run: |
bun test
bun run vscode:prepublish
- name: 🏷️ Manage label based on build result
if: ${{ always() && github.event_name == 'pull_request' }}
run: .github/scripts/update-status-label.sh ${{ github.event.pull_request.number }} ${{ steps.build.outcome }} "❌ failed build"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 10 additions & 1 deletion .github/workflows/color-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

permissions:
contents: read
pull-requests: write
issues: write # Update issue labels

jobs:
color-check:
Expand All @@ -19,9 +21,9 @@ jobs:
- name: πŸ“₯ Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
sparse-checkout-cone-mode: false
sparse-checkout: |
.github/scripts/update-status-label.sh
material-colors.yml
icons/
Expand All @@ -30,6 +32,13 @@ jobs:
git fetch origin $TARGET_BRANCH
- name: 🎨 Check colors
id: color-check
run: |
svgFiles=$(git diff origin/$TARGET_BRANCH --diff-filter=ACMRTUX --name-only | grep '.svg$')
npx svg-color-linter --config material-colors.yml ${svgFiles}
- name: 🏷️ Manage label based on color check result
if: always()
run: .github/scripts/update-status-label.sh ${{ github.event.pull_request.number }} ${{ steps.color-check.outcome }} "🎨 invalid colors"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 0 additions & 2 deletions .github/workflows/icon-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
path: fork
persist-credentials: false
sparse-checkout-cone-mode: false
sparse-checkout: |
icons/
Expand All @@ -36,7 +35,6 @@ jobs:
with:
fetch-depth: 0
path: main
persist-credentials: false
sparse-checkout-cone-mode: false
sparse-checkout: |
.bun-version
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

permissions:
pull-requests: write
issues: write # Update issue labels

jobs:
lint-pr-title:
Expand All @@ -21,13 +22,21 @@ jobs:
# Only fetch the config file from the repository
sparse-checkout-cone-mode: false
sparse-checkout: |
.github/scripts/update-status-label.sh
commitlint.config.js
- name: πŸ“¦ Install dependencies
run: npm install --global @commitlint/config-conventional commitlint

- name: πŸ” Check PR title with commitlint
id: title-check
env:
PR_TITLE: ${{ github.event.pull_request.title }}
HELP_URL: https://github.com/material-extensions/vscode-material-icon-theme/blob/main/CONTRIBUTING.md#conventional-pull-request-titles
run: echo "$PR_TITLE" | npx commitlint --help-url $HELP_URL

- name: 🏷️ Manage label based on PR title check result
if: always()
run: .github/scripts/update-status-label.sh ${{ github.event.pull_request.number }} ${{ steps.title-check.outcome }} "πŸ”€ invalid title"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 930dc09

Please sign in to comment.