Skip to content

Commit 2707312

Browse files
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 cd05e7c commit 2707312

File tree

5 files changed

+692
-18
lines changed

5 files changed

+692
-18
lines changed

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

Lines changed: 154 additions & 0 deletions
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: 12.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+
- tooling.yml
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 }}

.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
@@ -2,6 +2,7 @@
22

33
[![Check npm Dependencies status](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-dependencies-task.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-dependencies-task.yml)
44
![test](https://github.com/arduino/setup-protoc/workflows/test/badge.svg)
5+
[![Sync Labels status](https://github.com/arduino/setup-protoc/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/sync-labels-npm.yml)
56

67
This action makes the `protoc` compiler available to Workflows.
78

0 commit comments

Comments
 (0)