Skip to content

Commit

Permalink
Merge pull request #122 from woocommerce/update/108-nodejs-v20-github…
Browse files Browse the repository at this point in the history
…-actions-branch-label

Upgrade the `branch-label` action to use Node.js v20
  • Loading branch information
eason9487 authored May 9, 2024
2 parents 14e1521 + 424eada commit a51305f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 45 deletions.
36 changes: 34 additions & 2 deletions packages/github-actions/actions/branch-label/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,44 @@ See [action.yml](action.yml)

```yaml
on:
pull_request:
pull_request_target:
types: opened

jobs:
SetLabels:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Set Labels
uses: woocommerce/grow/branch-label@actions-v1
uses: woocommerce/grow/branch-label@actions-v2
```
#### Permissions:
In order to add labels to pull requests, this action requires write permissions on the pull request. However, when the action runs on a pull request from a fork, GitHub only grants read access tokens for the `pull_request` event. Therefore, it's recommended to use the `pull_request_target` event instead of `pull_request` to avoid the issue of not having permission.

Ref:
- https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
- https://github.com/actions/labeler/tree/v5#usage
- https://github.com/actions/labeler/tree/v5#permissions

## Migration from v1 to v2:

```diff
- pull_request:
+ pull_request_target:
types: opened
jobs:
SetLabels:
+ permissions:
+ contents: read
+ pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Set Labels
- uses: woocommerce/grow/branch-label@actions-v1
+ uses: woocommerce/grow/branch-label@actions-v2
```
51 changes: 8 additions & 43 deletions packages/github-actions/actions/branch-label/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,11 @@ description: Set PR labels according to the branch name.
runs:
using: composite
steps:
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'breaking/') }}
with:
labels: |
changelog: breaking
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'add/') }}
with:
labels: |
type: enhancement
changelog: add
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'update/') }}
with:
labels: |
changelog: update
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'fix/') }}
with:
labels: |
type: bug
changelog: fix
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'tweak/') }}
with:
labels: |
changelog: tweak
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'dev/') }}
with:
labels: |
changelog: dev
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'doc/') }}
with:
labels: |
changelog: doc
type: documentation
- uses: actions-ecosystem/action-add-labels@v1
if: ${{ startsWith(github.head_ref, 'release/') }}
with:
labels: |
changelog: none
# Copy labeler.yml to the default config path of `actions/labeler`.
- shell: bash
run: |
CONFIG_DIR=.github
mkdir -p "$CONFIG_DIR"
cp "${{ github.action_path }}/labeler.yml" "$CONFIG_DIR"
- uses: actions/labeler@v5
27 changes: 27 additions & 0 deletions packages/github-actions/actions/branch-label/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"changelog: breaking":
- head-branch: "^breaking/"

"changelog: add": &head-branch-add
- head-branch: "^add/"

"changelog: update":
- head-branch: "^update/"

"changelog: fix": &head-branch-fix
- head-branch: "^fix/"

"changelog: tweak":
- head-branch: "^tweak/"

"changelog: dev":
- head-branch: "^dev/"

"changelog: doc": &head-branch-doc
- head-branch: "^doc/"

"changelog: none":
- head-branch: "^release/"

"type: enhancement": *head-branch-add
"type: bug": *head-branch-fix
"type: documentation": *head-branch-doc

0 comments on commit a51305f

Please sign in to comment.