Skip to content

Commit 6d599e1

Browse files
committed
[skip changelog] 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 c9f790e commit 6d599e1

File tree

4 files changed

+159
-1
lines changed

4 files changed

+159
-1
lines changed

.github/dependabot.yml

+4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ updates:
1313
- dependency-name: github.com/sirupsen/logrus
1414
versions:
1515
- 1.7.1
16+
labels:
17+
- "topic: infrastructure"
1618
- package-ecosystem: github-actions
1719
directory: "/"
1820
schedule:
1921
interval: daily
2022
open-pull-requests-limit: 10
23+
labels:
24+
- "topic: infrastructure"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Used by the "Sync Labels" workflow
2+
# See: https://github.com/Financial-Times/github-label-sync#label-config-file
3+
4+
- name: "conclusion: stale"
5+
color: "940404"
6+
description: Closed due to lack of activity
7+
notes: |
8+
Added by the "Close stale issues" workflow.
9+
- name: "status: stale"
10+
color: "940404"
11+
description: Pending closure due to lack of activity
12+
notes: |
13+
Added by the "Close stale issues" workflow.

.github/workflows/close-stale-issues.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ jobs:
99
steps:
1010
- uses: actions/stale@v3
1111
with:
12-
stale-issue-message: 'This issue has been marked as stale because it has been open 14 days with no activity. Remove stale label or comment, otherwise it will be closed in 7 days '
12+
stale-issue-message: 'This issue has been marked as stale because it has been open 14 days with no activity. Remove **status: stale** label or comment, otherwise it will be closed in 7 days '
13+
close-issue-label: 'status: stale'
1314
close-issue-message: 'This issue has been closed becasue has been stale for 7 days. If you think this issue deserves some attention feel free to reopen it'
15+
close-issue-label: 'conclusion: stale'
1416
days-before-stale: 14
1517
days-before-close: 7
1618
days-before-pr-close: -1

.github/workflows/sync-labels.yml

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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/en/actions/reference/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+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v2
31+
32+
- name: Download JSON schema for labels configuration file
33+
id: download-schema
34+
uses: carlosperate/[email protected]
35+
with:
36+
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json
37+
location: ${{ runner.temp }}/label-configuration-schema
38+
39+
- name: Install JSON schema validator
40+
run: |
41+
sudo npm install \
42+
--global \
43+
ajv-cli \
44+
ajv-formats
45+
46+
- name: Validate local labels configuration
47+
run: |
48+
# 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}"
54+
55+
download:
56+
needs: check
57+
runs-on: ubuntu-latest
58+
59+
strategy:
60+
matrix:
61+
filename:
62+
# Filenames of the shared configurations to apply to the repository in addition to the local configuration.
63+
# https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels
64+
- universal.yml
65+
- tooling.yml
66+
67+
steps:
68+
- name: Download
69+
uses: carlosperate/[email protected]
70+
with:
71+
file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }}
72+
73+
- name: Pass configuration files to next job via workflow artifact
74+
uses: actions/upload-artifact@v2
75+
with:
76+
path: |
77+
*.yaml
78+
*.yml
79+
if-no-files-found: error
80+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
81+
82+
sync:
83+
needs: download
84+
runs-on: ubuntu-latest
85+
86+
steps:
87+
- name: Set environment variables
88+
run: |
89+
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
90+
echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV"
91+
92+
- name: Determine whether to dry run
93+
id: dry-run
94+
if: >
95+
github.event_name == 'pull_request' ||
96+
(
97+
(
98+
github.event_name == 'push' ||
99+
github.event_name == 'workflow_dispatch'
100+
) &&
101+
github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
102+
)
103+
run: |
104+
# Use of this flag in the github-label-sync command will cause it to only check the validity of the
105+
# configuration.
106+
echo "::set-output name=flag::--dry-run"
107+
108+
- name: Checkout repository
109+
uses: actions/checkout@v2
110+
111+
- name: Download configuration files artifact
112+
uses: actions/download-artifact@v2
113+
with:
114+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
115+
path: ${{ env.CONFIGURATIONS_FOLDER }}
116+
117+
- name: Remove unneeded artifact
118+
uses: geekyeggo/delete-artifact@v1
119+
with:
120+
name: ${{ env.CONFIGURATIONS_ARTIFACT }}
121+
122+
- name: Merge label configuration files
123+
run: |
124+
# Merge all configuration files
125+
shopt -s extglob
126+
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"
127+
128+
- name: Install github-label-sync
129+
run: sudo npm install --global github-label-sync
130+
131+
- name: Sync labels
132+
env:
133+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134+
run: |
135+
# 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 }}

0 commit comments

Comments
 (0)