Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the branch-label action to use Node.js v20 #122

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are using the labeler action, I think this link can be useful too: https://github.com/actions/labeler?tab=readme-ov-file#usage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 424eada.


## 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