From 404f22a54d97e7700ecb20be1a8f613c83c4e222 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 11 Jan 2024 06:47:17 +0100 Subject: [PATCH] Add CI workflow to synchronize with shared repository labels (#21) 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. --- .github/workflows/sync-labels-npm.yml | 160 ++++++++++++++++++++++++++ README.md | 3 +- 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/sync-labels-npm.yml diff --git a/.github/workflows/sync-labels-npm.yml b/.github/workflows/sync-labels-npm.yml new file mode 100644 index 0000000..a6714cd --- /dev/null +++ b/.github/workflows/sync-labels-npm.yml @@ -0,0 +1,160 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/sync-labels-npm.md +name: Sync Labels + +env: + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 16.x + 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-npm.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + - "package.json" + - "package-lock.json" + pull_request: + paths: + - ".github/workflows/sync-labels-npm.ya?ml" + - ".github/label-configuration-files/*.ya?ml" + - "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: + +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: ${{ env.NODE_VERSION }} + + - name: Download JSON schema for labels configuration file + id: download-schema + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/arduino-tooling-gh-label-configuration-schema.json + location: ${{ runner.temp }}/label-configuration-schema + + - name: Install JSON schema validator + run: npm install + + - name: Validate local labels configuration + run: | + # See: https://github.com/ajv-validator/ajv-cli#readme + 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 + + steps: + - name: Download + uses: carlosperate/download-file-action@v2 + with: + file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} + + - name: Pass configuration files to next job via workflow artifact + uses: actions/upload-artifact@v3 + with: + path: | + *.yaml + *.yml + if-no-files-found: error + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + sync: + needs: download + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + + steps: + - name: Set environment variables + run: | + # 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 + id: dry-run + if: > + github.event_name == 'pull_request' || + ( + ( + github.event_name == 'push' || + github.event_name == 'workflow_dispatch' + ) && + github.ref != format('refs/heads/{0}', github.event.repository.default_branch) + ) + run: | + # Use of this flag in the github-label-sync command will cause it to only check the validity of the + # configuration. + echo "flag=--dry-run" >> $GITHUB_OUTPUT + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download configuration files artifact + uses: actions/download-artifact@v3 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + path: ${{ env.CONFIGURATIONS_FOLDER }} + + - name: Remove unneeded artifact + uses: geekyeggo/delete-artifact@v2 + with: + name: ${{ env.CONFIGURATIONS_ARTIFACT }} + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + + - 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: npm install + + - name: Sync labels + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # See: https://github.com/Financial-Times/github-label-sync + npx \ + github-label-sync \ + --labels "${{ env.MERGED_CONFIGURATION_PATH }}" \ + ${{ steps.dry-run.outputs.flag }} \ + ${{ github.repository }} diff --git a/README.md b/README.md index 767ccb1..e7ecaf6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Arduino_GigaDisplay =================== [![Spell Check status](https://github.com/arduino-libraries/Arduino_GigaDisplay/actions/workflows/spell-check-task.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_GigaDisplay/actions/workflows/spell-check-task.yml) +[![Sync Labels status](https://github.com/arduino-libraries/Arduino_GigaDisplay/actions/workflows/sync-labels-npm.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_GigaDisplay/actions/workflows/sync-labels-npm.yml) This library contains a set of examples to use the [GIGA Display Shield](docs.arduino.cc/hardware/giga-display-shield). Upon installing this library from the Arduino IDE, the following libraries will also be installed: - [ArduinoGraphics](https://github.com/arduino-libraries/ArduinoGraphics) @@ -14,4 +15,4 @@ It will also install the [lvgl](https://github.com/lvgl/lvgl) library, which is ## GigaDisplayRGB -This library has a class called `GigaDisplayRGB`, which is used to control the built-in RGB on the GIGA Display Shield via the IS31FL3197 driver (I2C). \ No newline at end of file +This library has a class called `GigaDisplayRGB`, which is used to control the built-in RGB on the GIGA Display Shield via the IS31FL3197 driver (I2C).