Skip to content

Commit 1cf74ef

Browse files
committed
Migrate to npm-based GitHub label sync infrastructure
1 parent 26e1a67 commit 1cf74ef

File tree

3 files changed

+1666
-39
lines changed

3 files changed

+1666
-39
lines changed

.github/workflows/sync-labels.yml renamed to .github/workflows/sync-labels-npm.yml

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,47 @@
1-
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels-npm.md
22
name: Sync Labels
33

4-
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
4+
env:
5+
CONFIGURATIONS_FOLDER: .github/label-configuration-files
6+
CONFIGURATIONS_ARTIFACT: label-configuration-files
7+
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
59
on:
610
push:
711
paths:
8-
- ".github/workflows/sync-labels.ya?ml"
12+
- ".github/workflows/sync-labels-npm.ya?ml"
913
- ".github/label-configuration-files/*.ya?ml"
14+
- ".npmrc"
15+
- "package.json"
16+
- "package-lock.json"
1017
pull_request:
1118
paths:
12-
- ".github/workflows/sync-labels.ya?ml"
19+
- ".github/workflows/sync-labels-npm.ya?ml"
1320
- ".github/label-configuration-files/*.ya?ml"
21+
- ".npmrc"
22+
- "package.json"
23+
- "package-lock.json"
1424
schedule:
1525
# Run daily at 8 AM UTC to sync with changes to shared label configurations.
1626
- cron: "0 8 * * *"
1727
workflow_dispatch:
1828
repository_dispatch:
1929

20-
env:
21-
CONFIGURATIONS_FOLDER: .github/label-configuration-files
22-
CONFIGURATIONS_ARTIFACT: label-configuration-files
23-
2430
jobs:
2531
check:
2632
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
2735

2836
steps:
2937
- name: Checkout repository
3038
uses: actions/checkout@v4
3139

40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version-file: package.json
44+
3245
- name: Download JSON schema for labels configuration file
3346
id: download-schema
3447
uses: carlosperate/download-file-action@v2
@@ -37,32 +50,32 @@ jobs:
3750
location: ${{ runner.temp }}/label-configuration-schema
3851

3952
- name: Install JSON schema validator
40-
run: |
41-
sudo npm install \
42-
--global \
43-
ajv-cli \
44-
ajv-formats
53+
run: npm install
4554

4655
- name: Validate local labels configuration
4756
run: |
4857
# See: https://github.com/ajv-validator/ajv-cli#readme
49-
ajv validate \
50-
--all-errors \
51-
-c ajv-formats \
52-
-s "${{ steps.download-schema.outputs.file-path }}" \
53-
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
58+
npx \
59+
--package=ajv-cli \
60+
--package=ajv-formats \
61+
ajv validate \
62+
--all-errors \
63+
-c ajv-formats \
64+
-s "${{ steps.download-schema.outputs.file-path }}" \
65+
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
5466
5567
download:
5668
needs: check
5769
runs-on: ubuntu-latest
70+
permissions: {}
5871

5972
strategy:
6073
matrix:
6174
filename:
6275
# Filenames of the shared configurations to apply to the repository in addition to the local configuration.
6376
# https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels
64-
- universal.yml
6577
- tooling.yml
78+
- universal.yml
6679

6780
steps:
6881
- name: Download
@@ -82,11 +95,14 @@ jobs:
8295
sync:
8396
needs: download
8497
runs-on: ubuntu-latest
98+
permissions:
99+
contents: read
100+
issues: write
85101

86102
steps:
87103
- name: Set environment variables
88104
run: |
89-
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
105+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
90106
echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV"
91107
92108
- name: Determine whether to dry run
@@ -103,7 +119,7 @@ jobs:
103119
run: |
104120
# Use of this flag in the github-label-sync command will cause it to only check the validity of the
105121
# configuration.
106-
echo "::set-output name=flag::--dry-run"
122+
echo "flag=--dry-run" >> $GITHUB_OUTPUT
107123
108124
- name: Checkout repository
109125
uses: actions/checkout@v4
@@ -119,21 +135,27 @@ jobs:
119135
with:
120136
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
121137

138+
- name: Setup Node.js
139+
uses: actions/setup-node@v4
140+
with:
141+
node-version-file: package.json
142+
122143
- name: Merge label configuration files
123144
run: |
124145
# Merge all configuration files
125146
shopt -s extglob
126147
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"
127148
128149
- name: Install github-label-sync
129-
run: sudo npm install --global github-label-sync
150+
run: npm install
130151

131152
- name: Sync labels
132153
env:
133154
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134155
run: |
135156
# See: https://github.com/Financial-Times/github-label-sync
136-
github-label-sync \
137-
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
138-
${{ steps.dry-run.outputs.flag }} \
139-
${{ github.repository }}
157+
npx \
158+
github-label-sync \
159+
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
160+
${{ steps.dry-run.outputs.flag }} \
161+
${{ github.repository }}

0 commit comments

Comments
 (0)