Skip to content

Commit a0b5dd3

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 5e30ae5 commit a0b5dd3

File tree

5 files changed

+1736
-0
lines changed

5 files changed

+1736
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Used by the "Sync Labels" workflow
2+
# See: https://github.com/Financial-Times/github-label-sync#label-config-file
3+
4+
- name: "topic: availability"
5+
color: "00ffff"
6+
description: Related to outage or degradation of web services
7+
- name: "topic: forum software"
8+
color: "00ffff"
9+
description: Related to configuration of the Arduino Forum software
10+
# Vulnerability disclosures are made following the procedure at:
11+
# https://github.com/arduino/.github/blob/master/SECURITY.md
12+
- name: "topic: security"
13+
color: ff0000
14+
description: Related to the protection of user data

.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: 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+
76+
steps:
77+
- name: Download
78+
uses: carlosperate/download-file-action@v2
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 "flag=--dry-run" >> $GITHUB_OUTPUT
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@v2
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 }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[![Check Workflows status](https://github.com/arduino/forum-assets/actions/workflows/check-workflows-task.yml/badge.svg)](https://github.com/arduino/forum-assets/actions/workflows/check-workflows-task.yml)
1010
[![Check YAML status](https://github.com/arduino/forum-assets/actions/workflows/check-yaml-task.yml/badge.svg)](https://github.com/arduino/forum-assets/actions/workflows/check-yaml-task.yml)
1111
[![Spell Check status](https://github.com/arduino/forum-assets/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino/forum-assets/actions/workflows/spell-check-task.yml)
12+
[![Sync Labels status](https://github.com/arduino/forum-assets/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino/forum-assets/actions/workflows/sync-labels-npm.yml)
1213

1314
This repository is used for collaborative development of the content of the important documentation content published in the [Arduino Forum](https://forum.arduino.cc) [pinned](https://meta.discourse.org/t/how-can-i-manually-pin-a-topic-to-the-top/95405) topics.
1415

0 commit comments

Comments
 (0)