Skip to content

Commit 5fa45b5

Browse files
committed
Add CI workflow to synchronize with shared repository labels
On every push that changes relevant files, and periodically, configure the repository's issue and pull request labels according to the universal, shared, and local label configuration files.
1 parent 6ebb6a9 commit 5fa45b5

File tree

6 files changed

+2288
-0
lines changed

6 files changed

+2288
-0
lines changed

.github/workflows/spell-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ jobs:
1414
uses: arduino/actions/libraries/spell-check@master
1515
with:
1616
ignore-words-list: etc/codespell-ignore-words-list.txt
17+
skip-paths: node_modules,package-lock.json

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

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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@v2
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+
- tooling.yml
76+
77+
steps:
78+
- name: Download
79+
uses: carlosperate/download-file-action@v2
80+
with:
81+
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }}
82+
83+
- name: Pass configuration files to next job via workflow artifact
84+
uses: actions/upload-artifact@v3
85+
with:
86+
path: |
87+
*.yaml
88+
*.yml
89+
if-no-files-found: error
90+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
91+
92+
sync:
93+
needs: download
94+
runs-on: ubuntu-latest
95+
96+
steps:
97+
- name: Set environment variables
98+
run: |
99+
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
100+
echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV"
101+
102+
- name: Determine whether to dry run
103+
id: dry-run
104+
if: >
105+
github.event_name == 'pull_request' ||
106+
(
107+
(
108+
github.event_name == 'push' ||
109+
github.event_name == 'workflow_dispatch'
110+
) &&
111+
github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
112+
)
113+
run: |
114+
# Use of this flag in the github-label-sync command will cause it to only check the validity of the
115+
# configuration.
116+
echo "flag=--dry-run" >> $GITHUB_OUTPUT
117+
118+
- name: Checkout repository
119+
uses: actions/checkout@v3
120+
121+
- name: Download configuration files artifact
122+
uses: actions/download-artifact@v3
123+
with:
124+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
125+
path: ${{ env.CONFIGURATIONS_FOLDER }}
126+
127+
- name: Remove unneeded artifact
128+
uses: geekyeggo/delete-artifact@v2
129+
with:
130+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
131+
132+
- name: Setup Node.js
133+
uses: actions/setup-node@v3
134+
with:
135+
node-version: ${{ env.NODE_VERSION }}
136+
137+
- name: Merge label configuration files
138+
run: |
139+
# Merge all configuration files
140+
shopt -s extglob
141+
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"
142+
143+
- name: Install github-label-sync
144+
run: npm install
145+
146+
- name: Sync labels
147+
env:
148+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
run: |
150+
# See: https://github.com/Financial-Times/github-label-sync
151+
npx \
152+
github-label-sync \
153+
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
154+
${{ steps.dry-run.outputs.flag }} \
155+
${{ github.repository }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Tests](https://github.com/arduino/report-size-deltas/workflows/libraries/report-size-deltas%20workflow/badge.svg)](https://github.com/arduino/report-size-deltas/actions?workflow=libraries/report-size-deltas+workflow)
44
[![Integration Tests](https://github.com/arduino/report-size-deltas/actions/workflows/test-integration.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/test-integration.yml)
55
[![Spell Check](https://github.com/arduino/report-size-deltas/workflows/Spell%20Check/badge.svg)](https://github.com/arduino/report-size-deltas/actions?workflow=Spell+Check)
6+
[![Sync Labels status](https://github.com/arduino/report-size-deltas/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/sync-labels-npm.yml)
67
[![codecov](https://codecov.io/gh/arduino/report-size-deltas/branch/master/graph/badge.svg)](https://codecov.io/gh/arduino/report-size-deltas)
78

89
This action comments on the pull request with a report on the resulting change in memory usage of the [Arduino](https://www.arduino.cc/) sketches compiled by the [`arduino/compile-sketches`](https://github.com/arduino/compile-sketches) action. This should be run from a [scheduled workflow](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule).

0 commit comments

Comments
 (0)