Skip to content

Commit 2e10c4f

Browse files
committed
Add a version of the "Sync Labels" workflow for npm-managed projects
We are now standardizing on the use of npm to manage tool dependencies of the assets. There is one drawback to that approach, which is that it requires the addition of the npm metadata files to the repository (if not already present). Two more files are not of any concern for the average Arduino tooling project. However, the "Sync Labels" workflow is already in widespread usage in other types of official Arduino projects. In some projects (e.g., Arduino libraries), where the contents are intended to be very approachable to less advanced users, the added files may be considered problematic, especially since, unlike all the other workflows that were candidates for npm-managed tools, the "Sync Labels" workflow did not require the addition of any files other than the GitHub Actions workflow (the others also require a taskfile at minimum). For this reason, the previous lightweight version of "Sync Labels" is retained, but another version added for use in projects where the dependency management is desired.
1 parent beb4f4b commit 2e10c4f

File tree

6 files changed

+467
-24
lines changed

6 files changed

+467
-24
lines changed

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

+38-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
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+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
CONFIGURATIONS_FOLDER: .github/label-configuration-files
8+
CONFIGURATIONS_ARTIFACT: label-configuration-files
9+
410
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
511
on:
612
push:
713
paths:
8-
- ".github/workflows/sync-labels.ya?ml"
14+
- ".github/workflows/sync-labels-npm.ya?ml"
915
- ".github/label-configuration-files/*.ya?ml"
16+
- "package.json"
17+
- "package-lock.json"
1018
pull_request:
1119
paths:
12-
- ".github/workflows/sync-labels.ya?ml"
20+
- ".github/workflows/sync-labels-npm.ya?ml"
1321
- ".github/label-configuration-files/*.ya?ml"
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
@@ -29,6 +35,11 @@ jobs:
2935
- name: Checkout repository
3036
uses: actions/checkout@v3
3137

38+
- name: Setup Node.js
39+
uses: actions/setup-node@v3
40+
with:
41+
node-version: ${{ env.NODE_VERSION }}
42+
3243
- name: Download JSON schema for labels configuration file
3344
id: download-schema
3445
uses: carlosperate/download-file-action@v1
@@ -37,20 +48,19 @@ jobs:
3748
location: ${{ runner.temp }}/label-configuration-schema
3849

3950
- name: Install JSON schema validator
40-
run: |
41-
sudo npm install \
42-
--global \
43-
ajv-cli \
44-
ajv-formats
51+
run: npm install
4552

4653
- name: Validate local labels configuration
4754
run: |
4855
# 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}"
56+
npx \
57+
--package=ajv-cli \
58+
--package=ajv-formats \
59+
ajv validate \
60+
--all-errors \
61+
-c ajv-formats \
62+
-s "${{ steps.download-schema.outputs.file-path }}" \
63+
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
5464
5565
download:
5666
needs: check
@@ -118,21 +128,27 @@ jobs:
118128
with:
119129
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
120130

131+
- name: Setup Node.js
132+
uses: actions/setup-node@v3
133+
with:
134+
node-version: ${{ env.NODE_VERSION }}
135+
121136
- name: Merge label configuration files
122137
run: |
123138
# Merge all configuration files
124139
shopt -s extglob
125140
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"
126141
127142
- name: Install github-label-sync
128-
run: sudo npm install --global github-label-sync
143+
run: npm install
129144

130145
- name: Sync labels
131146
env:
132147
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133148
run: |
134149
# See: https://github.com/Financial-Times/github-label-sync
135-
github-label-sync \
136-
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
137-
${{ steps.dry-run.outputs.flag }} \
138-
${{ github.repository }}
150+
npx \
151+
github-label-sync \
152+
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
153+
${{ steps.dry-run.outputs.flag }} \
154+
${{ github.repository }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[![Check Prettier Formatting status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-prettier-formatting-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-prettier-formatting-task.yml)
1616
[![Check Taskfiles status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-taskfiles.yml)
1717
[![Check YAML status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-yaml-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-yaml-task.yml)
18-
[![Sync Labels status](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels.yml)
18+
[![Sync Labels status](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/sync-labels-npm.yml)
1919
[![Check Workflows status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-workflows-task.yml)
2020
[![Spell Check status](https://github.com/arduino/tooling-project-assets/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/spell-check-task.yml)
2121
[![Check Python status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-python-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-python-task.yml)

Taskfile.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tasks:
4848
"{{.WORKFLOW_TEMPLATES_PATH}}/check-shell-task.yml" \
4949
"{{.WORKFLOW_TEMPLATES_PATH}}/check-taskfiles.yml" \
5050
"{{.WORKFLOW_TEMPLATES_PATH}}/check-yaml-task.yml" \
51-
"{{.WORKFLOW_TEMPLATES_PATH}}/sync-labels.yml" \
51+
"{{.WORKFLOW_TEMPLATES_PATH}}/sync-labels-npm.yml" \
5252
"{{.WORKFLOW_TEMPLATES_PATH}}/spell-check-task.yml" \
5353
"{{.WORKFLOW_TEMPLATES_PATH}}/test-python-poetry-task.yml" \
5454
"{{.WORKFLOWS_PATH}}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels-npm.md
2+
name: Sync Labels
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
CONFIGURATIONS_FOLDER: .github/label-configuration-files
8+
CONFIGURATIONS_ARTIFACT: label-configuration-files
9+
10+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
11+
on:
12+
push:
13+
paths:
14+
- ".github/workflows/sync-labels-npm.ya?ml"
15+
- ".github/label-configuration-files/*.ya?ml"
16+
- "package.json"
17+
- "package-lock.json"
18+
pull_request:
19+
paths:
20+
- ".github/workflows/sync-labels-npm.ya?ml"
21+
- ".github/label-configuration-files/*.ya?ml"
22+
- "package.json"
23+
- "package-lock.json"
24+
schedule:
25+
# Run daily at 8 AM UTC to sync with changes to shared label configurations.
26+
- cron: "0 8 * * *"
27+
workflow_dispatch:
28+
repository_dispatch:
29+
30+
jobs:
31+
check:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v3
37+
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v3
40+
with:
41+
node-version: ${{ env.NODE_VERSION }}
42+
43+
- name: Download JSON schema for labels configuration file
44+
id: download-schema
45+
uses: carlosperate/download-file-action@v1
46+
with:
47+
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json
48+
location: ${{ runner.temp }}/label-configuration-schema
49+
50+
- name: Install JSON schema validator
51+
run: npm install
52+
53+
- name: Validate local labels configuration
54+
run: |
55+
# See: https://github.com/ajv-validator/ajv-cli#readme
56+
npx \
57+
--package=ajv-cli \
58+
--package=ajv-formats \
59+
ajv validate \
60+
--all-errors \
61+
-c ajv-formats \
62+
-s "${{ steps.download-schema.outputs.file-path }}" \
63+
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
64+
65+
download:
66+
needs: check
67+
runs-on: ubuntu-latest
68+
69+
strategy:
70+
matrix:
71+
filename:
72+
# Filenames of the shared configurations to apply to the repository in addition to the local configuration.
73+
# https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels
74+
- universal.yml
75+
76+
steps:
77+
- name: Download
78+
uses: carlosperate/download-file-action@v1
79+
with:
80+
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }}
81+
82+
- name: Pass configuration files to next job via workflow artifact
83+
uses: actions/upload-artifact@v3
84+
with:
85+
path: |
86+
*.yaml
87+
*.yml
88+
if-no-files-found: error
89+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
90+
91+
sync:
92+
needs: download
93+
runs-on: ubuntu-latest
94+
95+
steps:
96+
- name: Set environment variables
97+
run: |
98+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
99+
echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV"
100+
101+
- name: Determine whether to dry run
102+
id: dry-run
103+
if: >
104+
github.event_name == 'pull_request' ||
105+
(
106+
(
107+
github.event_name == 'push' ||
108+
github.event_name == 'workflow_dispatch'
109+
) &&
110+
github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
111+
)
112+
run: |
113+
# Use of this flag in the github-label-sync command will cause it to only check the validity of the
114+
# configuration.
115+
echo "::set-output name=flag::--dry-run"
116+
117+
- name: Checkout repository
118+
uses: actions/checkout@v3
119+
120+
- name: Download configuration files artifact
121+
uses: actions/download-artifact@v3
122+
with:
123+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
124+
path: ${{ env.CONFIGURATIONS_FOLDER }}
125+
126+
- name: Remove unneeded artifact
127+
uses: geekyeggo/delete-artifact@v1
128+
with:
129+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
130+
131+
- name: Setup Node.js
132+
uses: actions/setup-node@v3
133+
with:
134+
node-version: ${{ env.NODE_VERSION }}
135+
136+
- name: Merge label configuration files
137+
run: |
138+
# Merge all configuration files
139+
shopt -s extglob
140+
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"
141+
142+
- name: Install github-label-sync
143+
run: npm install
144+
145+
- name: Sync labels
146+
env:
147+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148+
run: |
149+
# See: https://github.com/Financial-Times/github-label-sync
150+
npx \
151+
github-label-sync \
152+
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
153+
${{ steps.dry-run.outputs.flag }} \
154+
${{ github.repository }}

0 commit comments

Comments
 (0)