Skip to content

Commit f189a03

Browse files
Merge pull request #5 from arduino/sync-labels
Add CI workflow to synchronize with shared repository labels
2 parents 3518634 + 3e5fd8e commit f189a03

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

.github/workflows/sync-labels.yml

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

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[![Go Reference](https://pkg.go.dev/badge/github.com/arduino/fwuploader-plugin-helper.svg)](https://pkg.go.dev/github.com/arduino/fwuploader-plugin-helper)
66
[![Check Go status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/check-go-task.yml)
7+
[![Sync Labels status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/sync-labels.yml)
78

89
<!--[![Test Go status](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/test-go-task.yml/badge.svg)](https://github.com/arduino/fwuploader-plugin-helper/actions/workflows/test-go-task.yml)-->
910
<!--[![Codecov](https://codecov.io/gh/arduino/fwuploader-plugin-helper/branch/main/graph/badge.svg)](https://codecov.io/gh/arduino/fwuploader-plugin-helper)-->

0 commit comments

Comments
 (0)