Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Migrate to npm-based GitHub label sync infrastructure
  • Loading branch information
per1234 committed Oct 7, 2024
commit 1cf74ef1a8b210a981ba31bf6a874468e419829d
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels.md
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels-npm.md
name: Sync Labels

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
env:
CONFIGURATIONS_FOLDER: .github/label-configuration-files
CONFIGURATIONS_ARTIFACT: label-configuration-files

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/sync-labels.ya?ml"
- ".github/workflows/sync-labels-npm.ya?ml"
- ".github/label-configuration-files/*.ya?ml"
- ".npmrc"
- "package.json"
- "package-lock.json"
pull_request:
paths:
- ".github/workflows/sync-labels.ya?ml"
- ".github/workflows/sync-labels-npm.ya?ml"
- ".github/label-configuration-files/*.ya?ml"
- ".npmrc"
- "package.json"
- "package-lock.json"
schedule:
# Run daily at 8 AM UTC to sync with changes to shared label configurations.
- cron: "0 8 * * *"
workflow_dispatch:
repository_dispatch:

env:
CONFIGURATIONS_FOLDER: .github/label-configuration-files
CONFIGURATIONS_ARTIFACT: label-configuration-files

jobs:
check:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json

- name: Download JSON schema for labels configuration file
id: download-schema
uses: carlosperate/download-file-action@v2
Expand All @@ -37,32 +50,32 @@ jobs:
location: ${{ runner.temp }}/label-configuration-schema

- name: Install JSON schema validator
run: |
sudo npm install \
--global \
ajv-cli \
ajv-formats
run: npm install

- name: Validate local labels configuration
run: |
# See: https://github.com/ajv-validator/ajv-cli#readme
ajv validate \
--all-errors \
-c ajv-formats \
-s "${{ steps.download-schema.outputs.file-path }}" \
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"
npx \
--package=ajv-cli \
--package=ajv-formats \
ajv validate \
--all-errors \
-c ajv-formats \
-s "${{ steps.download-schema.outputs.file-path }}" \
-d "${{ env.CONFIGURATIONS_FOLDER }}/*.{yml,yaml}"

download:
needs: check
runs-on: ubuntu-latest
permissions: {}

strategy:
matrix:
filename:
# Filenames of the shared configurations to apply to the repository in addition to the local configuration.
# https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/sync-labels
- universal.yml
- tooling.yml
- universal.yml

steps:
- name: Download
Expand All @@ -82,11 +95,14 @@ jobs:
sync:
needs: download
runs-on: ubuntu-latest
permissions:
contents: read
issues: write

steps:
- name: Set environment variables
run: |
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
# See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
echo "MERGED_CONFIGURATION_PATH=${{ runner.temp }}/labels.yml" >> "$GITHUB_ENV"

- name: Determine whether to dry run
Expand All @@ -103,7 +119,7 @@ jobs:
run: |
# Use of this flag in the github-label-sync command will cause it to only check the validity of the
# configuration.
echo "::set-output name=flag::--dry-run"
echo "flag=--dry-run" >> $GITHUB_OUTPUT

- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -119,21 +135,27 @@ jobs:
with:
name: ${{ env.CONFIGURATIONS_ARTIFACT }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: package.json

- name: Merge label configuration files
run: |
# Merge all configuration files
shopt -s extglob
cat "${{ env.CONFIGURATIONS_FOLDER }}"/*.@(yml|yaml) > "${{ env.MERGED_CONFIGURATION_PATH }}"

- name: Install github-label-sync
run: sudo npm install --global github-label-sync
run: npm install

- name: Sync labels
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# See: https://github.com/Financial-Times/github-label-sync
github-label-sync \
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
${{ steps.dry-run.outputs.flag }} \
${{ github.repository }}
npx \
github-label-sync \
--labels "${{ env.MERGED_CONFIGURATION_PATH }}" \
${{ steps.dry-run.outputs.flag }} \
${{ github.repository }}
Loading