Skip to content

Commit 8aba048

Browse files
committed
Switch to version of the "Sync Labels" workflow for npm-managed projects
The "Sync Labels" workflow was originally developed with Arduino firmware repositories in mind. Those projects don't have a lot of existing infrastructure and, since they are intended to be very approachable, the impact of adding additional non-firmware files or folders (especially in the root) must be carefully considered. In that context, a self-contained workflow is desirable. However, the situation is different in the inherently more complex and infrastructure rich tooling projects, which are typically consumed only as a binary by users. For this reason, an alternative standardized version of the "Sync Labels" workflow was produced, which utilizes npm to manage its tool dependencies. The code dependencies of this project and the code infrastructure are already managed via npm, which means the switch to this superior version of the workflow can be made without the need to add any additional infrastructure. This provides some significant benefits: - Controlled updates via Dependabot PRs instead of being subject to immediate breakage resulting from a new tool release - Enables automated vulnerability alerts This is especially important for the github-label-sync tool, since it is making irreversible writes to the GitHub repository.
1 parent 3bb910e commit 8aba048

File tree

4 files changed

+1793
-28
lines changed

4 files changed

+1793
-28
lines changed

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

Lines changed: 40 additions & 24 deletions
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-
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
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
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@v2
@@ -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
@@ -86,7 +96,7 @@ jobs:
8696
steps:
8797
- name: Set environment variables
8898
run: |
89-
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
99+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
90100
echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV"
91101
92102
- name: Determine whether to dry run
@@ -119,21 +129,27 @@ jobs:
119129
with:
120130
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
121131

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

131146
- name: Sync labels
132147
env:
133148
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134149
run: |
135150
# 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 }}
151+
npx \
152+
github-label-sync \
153+
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
154+
${{ steps.dry-run.outputs.flag }} \
155+
${{ github.repository }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[![Spell Check status](https://github.com/arduino/setup-task/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/setup-task/actions/workflows/spell-check-task.yml)
1212
[![Check License status](https://github.com/arduino/setup-task/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/setup-task/actions/workflows/check-license.yml)
1313
[![Check npm Dependencies status](https://github.com/arduino/setup-task/actions/workflows/check-npm-dependencies-task.yml/badge.svg)](https://github.com/arduino/setup-task/actions/workflows/check-npm-dependencies-task.yml)
14+
[![Sync Labels status](https://github.com/arduino/setup-task/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/setup-task/actions/workflows/sync-labels-npm.yml)
1415

1516
A [GitHub Actions](https://docs.github.com/en/actions) action that makes the [Task](https://taskfile.dev/#/) task runner / build tool available to use in your workflow.
1617

0 commit comments

Comments
 (0)