From c8b952727fc3ed71ceae19795327d871d2c72b46 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 13 Jun 2021 15:28:37 -0700 Subject: [PATCH] Use a task for syncing file duplicates This repository contains intentionally duplicated template workflow copies under `workflow-templates/dependabot/workflow-template-copies`. These are used for the Dependabot checks for outdated action versions. It's essential that these be kept in sync with the source files, and this is enforced by a CI workflow. So the sync process will need to be run by the developer whenever modifying the template workflows. A Bash script was previously provided to facilitate syncing, and used by the CI system. However, the Tooling Team standard is to use Task for development processes that are regularly run locally. So a Task-based approach is most appropriate. --- .github/workflows/check-sync.yml | 18 ++++++++++++++---- Taskfile.yml | 21 +++++++++++++++++++++ etc/sync.sh | 13 ------------- 3 files changed, 35 insertions(+), 17 deletions(-) delete mode 100755 etc/sync.sh diff --git a/.github/workflows/check-sync.yml b/.github/workflows/check-sync.yml index 074c1dab..c06a3854 100644 --- a/.github/workflows/check-sync.yml +++ b/.github/workflows/check-sync.yml @@ -4,7 +4,7 @@ # - Assets for the workflow templates used in this repository. # # This workflow checks that the copies are in sync. -# If the workflow fails, run workflow-templates/etc/sync.sh and commit. +# If the workflow fails, run `task dependabot:sync` and commit. name: Check File Duplicates Sync @@ -16,16 +16,26 @@ jobs: check-sync: runs-on: ubuntu-latest + env: + SYNC_COMMAND: task dependabot:sync + steps: - name: Checkout repository uses: actions/checkout@v2 + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Sync files + run: ${{ env.SYNC_COMMAND }} --silent + - name: Check file duplicates sync run: | - SYNC_SCRIPT_PATH="etc/sync.sh" - "${{ github.workspace }}/$SYNC_SCRIPT_PATH" git add . if ! git diff --color --exit-code HEAD; then - echo "::error::File duplicates are out of sync. Please run $SYNC_SCRIPT_PATH" + echo "::error::File duplicates are out of sync. Please run \"${{ env.SYNC_COMMAND }}\"" exit 1 fi diff --git a/Taskfile.yml b/Taskfile.yml index 4474bf9b..5c8bfd99 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,11 +1,32 @@ version: "3" tasks: + fix: + desc: Make automated corrections to the project's files + deps: + - task: dependabot:sync + check: desc: Check for problems with the project deps: - task: config:validate + dependabot:sync: + desc: Sync workflow duplicates for dependabot checks + vars: + WORKFLOW_TEMPLATES_PATH: "./workflow-templates" + WORKFLOW_TEMPLATE_COPIES_PATH: "./workflow-templates/dependabot/workflow-template-copies/.github/workflows" + cmds: + # Sync workflow templates with the copies in the folder where Dependabot can check them for updates. + - mkdir --parents "{{.WORKFLOW_TEMPLATE_COPIES_PATH}}" + - rm --force "{{.WORKFLOW_TEMPLATE_COPIES_PATH}}"/* + - | + find "{{.WORKFLOW_TEMPLATES_PATH}}" \ + -maxdepth 1 \ + -type f \ + -regex '.*\.ya?ml' \ + -exec cp '{}' "{{.WORKFLOW_TEMPLATE_COPIES_PATH}}" \; + config:validate: desc: Validate configuration files against their JSON schema vars: diff --git a/etc/sync.sh b/etc/sync.sh deleted file mode 100755 index 70d6fc6e..00000000 --- a/etc/sync.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -# Sync the repository's intentionally duplicated files. - -readonly REPOSITORY_ROOT_PATH="$(git rev-parse --show-toplevel)" -readonly WORKFLOW_TEMPLATE_ASSETS_PATH="${REPOSITORY_ROOT_PATH}/workflow-templates/assets" -readonly WORKFLOW_TEMPLATES_PATH="${REPOSITORY_ROOT_PATH}/workflow-templates" -readonly WORKFLOWS_PATH="${REPOSITORY_ROOT_PATH}/.github/workflows" -readonly WORKFLOW_TEMPLATE_COPIES_PATH="${REPOSITORY_ROOT_PATH}/workflow-templates/dependabot/workflow-template-copies/.github/workflows" - -# Sync workflow templates with the copies in the folder where Dependabot can check them for updates. -mkdir --parents "$WORKFLOW_TEMPLATE_COPIES_PATH" -rm --force "${WORKFLOW_TEMPLATE_COPIES_PATH}/"* -find "$WORKFLOW_TEMPLATES_PATH" -maxdepth 1 -type f -and \( -name '*.yml' -or -name '*.yaml' \) -exec cp '{}' "$WORKFLOW_TEMPLATE_COPIES_PATH" \;