Skip to content

Commit 9595935

Browse files
authored
Merge pull request #30 from per1234/sync-labels
Add CI workflow to synchronize with shared repository labels
2 parents 1cb4a4f + d6b001b commit 9595935

File tree

10 files changed

+2617
-0
lines changed

10 files changed

+2617
-0
lines changed

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ updates:
1414
labels:
1515
- "topic: infrastructure"
1616

17+
- package-ecosystem: npm
18+
assignees:
19+
- per1234
20+
directory: /
21+
schedule:
22+
interval: daily
23+
labels:
24+
- "topic: infrastructure"
25+
1726
- package-ecosystem: pip
1827
assignees:
1928
- per1234

.github/workflows/check-npm-task.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-npm-task.md
2+
name: Check npm
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-npm-task.ya?ml"
14+
- "**/package.json"
15+
- "**/package-lock.json"
16+
- "Taskfile.ya?ml"
17+
pull_request:
18+
paths:
19+
- ".github/workflows/check-npm-task.ya?ml"
20+
- "**/package.json"
21+
- "**/package-lock.json"
22+
- "Taskfile.ya?ml"
23+
schedule:
24+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
25+
- cron: "0 8 * * TUE"
26+
workflow_dispatch:
27+
repository_dispatch:
28+
29+
permissions:
30+
contents: read
31+
32+
jobs:
33+
run-determination:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
result: ${{ steps.determination.outputs.result }}
37+
steps:
38+
- name: Determine if the rest of the workflow should run
39+
id: determination
40+
run: |
41+
RELEASE_BRANCH_REGEX="^refs/heads/v[0-9]+$"
42+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
43+
if [[
44+
"${{ github.event_name }}" != "create" ||
45+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
46+
]]; then
47+
# Run the other jobs.
48+
RESULT="true"
49+
else
50+
# There is no need to run the other jobs.
51+
RESULT="false"
52+
fi
53+
54+
echo "result=$RESULT" >> $GITHUB_OUTPUT
55+
56+
validate:
57+
needs: run-determination
58+
if: needs.run-determination.outputs.result == 'true'
59+
runs-on: ubuntu-latest
60+
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v3
64+
65+
- name: Setup Node.js
66+
uses: actions/setup-node@v3
67+
with:
68+
node-version: ${{ env.NODE_VERSION }}
69+
70+
- name: Install Task
71+
uses: arduino/setup-task@v1
72+
with:
73+
repo-token: ${{ secrets.GITHUB_TOKEN }}
74+
version: 3.x
75+
76+
- name: Validate package.json
77+
run: task --silent npm:validate
78+
79+
check-sync:
80+
needs: run-determination
81+
if: needs.run-determination.outputs.result == 'true'
82+
runs-on: ubuntu-latest
83+
84+
steps:
85+
- name: Checkout repository
86+
uses: actions/checkout@v3
87+
88+
- name: Setup Node.js
89+
uses: actions/setup-node@v3
90+
with:
91+
node-version: ${{ env.NODE_VERSION }}
92+
93+
- name: Install Task
94+
uses: arduino/setup-task@v1
95+
with:
96+
repo-token: ${{ secrets.GITHUB_TOKEN }}
97+
version: 3.x
98+
99+
- name: Install npm dependencies
100+
run: task npm:install-deps
101+
102+
- name: Check package-lock.json
103+
run: git diff --color --exit-code package-lock.json

.github/workflows/check-taskfiles.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-taskfiles.md
2+
name: Check Taskfiles
3+
4+
env:
5+
# See: https://github.com/actions/setup-node/#readme
6+
NODE_VERSION: 16.x
7+
8+
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
9+
on:
10+
create:
11+
push:
12+
paths:
13+
- ".github/workflows/check-taskfiles.ya?ml"
14+
- "package.json"
15+
- "package-lock.json"
16+
- "**/Taskfile.ya?ml"
17+
pull_request:
18+
paths:
19+
- ".github/workflows/check-taskfiles.ya?ml"
20+
- "package.json"
21+
- "package-lock.json"
22+
- "**/Taskfile.ya?ml"
23+
schedule:
24+
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema.
25+
- cron: "0 8 * * TUE"
26+
workflow_dispatch:
27+
repository_dispatch:
28+
29+
jobs:
30+
run-determination:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
result: ${{ steps.determination.outputs.result }}
34+
steps:
35+
- name: Determine if the rest of the workflow should run
36+
id: determination
37+
run: |
38+
RELEASE_BRANCH_REGEX="^refs/heads/v[0-9]+$"
39+
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
40+
if [[
41+
"${{ github.event_name }}" != "create" ||
42+
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
43+
]]; then
44+
# Run the other jobs.
45+
RESULT="true"
46+
else
47+
# There is no need to run the other jobs.
48+
RESULT="false"
49+
fi
50+
51+
echo "result=$RESULT" >> $GITHUB_OUTPUT
52+
53+
validate:
54+
name: Validate ${{ matrix.file }}
55+
needs: run-determination
56+
if: needs.run-determination.outputs.result == 'true'
57+
runs-on: ubuntu-latest
58+
59+
strategy:
60+
fail-fast: false
61+
62+
matrix:
63+
file:
64+
- ./**/Taskfile.yml
65+
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v3
69+
70+
- name: Setup Node.js
71+
uses: actions/setup-node@v3
72+
with:
73+
node-version: ${{ env.NODE_VERSION }}
74+
75+
- name: Download JSON schema for Taskfiles
76+
id: download-schema
77+
uses: carlosperate/download-file-action@v2
78+
with:
79+
# Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/taskfile.json
80+
file-url: https://taskfile.dev/schema.json
81+
location: ${{ runner.temp }}/taskfile-schema
82+
83+
- name: Install JSON schema validator
84+
run: npm install
85+
86+
- name: Validate ${{ matrix.file }}
87+
run: |
88+
# See: https://github.com/ajv-validator/ajv-cli#readme
89+
npx \
90+
--package=ajv-cli \
91+
--package=ajv-formats \
92+
ajv validate \
93+
--all-errors \
94+
--strict=false \
95+
-c ajv-formats \
96+
-s "${{ steps.download-schema.outputs.file-path }}" \
97+
-d "${{ matrix.file }}"

.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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# `arduino/report-size-deltas` action
22

3+
[![Check npm status](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-npm-task.yml)
4+
[![Check Taskfiles status](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml/badge.svg)](https://github.com/arduino/report-size-deltas/actions/workflows/check-taskfiles.yml)
35
[![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)
46
[![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)
57
[![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)
8+
[![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)
69
[![codecov](https://codecov.io/gh/arduino/report-size-deltas/branch/master/graph/badge.svg)](https://codecov.io/gh/arduino/report-size-deltas)
710

811
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)