From 1ac01d728d93f634367b6482870b85726299784f Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Tue, 1 Sep 2026 12:14:36 -0400 Subject: [PATCH] Add build workflow Adds dry_run and path inputs so CI can run the action against a throwaway copier project without pushing a branch or opening a pull request. The fixture lives under RUNNER_TEMP because the action checks out the repo itself, which would clean anything staged in the workspace. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com> --- .github/workflows/build.yaml | 75 ++++++++++++++++++++++++++++++++++++ update/action.yml | 15 +++++++- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..3c3d7db --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,75 @@ +name: Build Status + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Build a copier template and a project generated from it + run: | + set -eux + git config --global user.name "github-actions" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global init.defaultBranch main + pip install copier + + mkdir -p "$TEMPLATE" + cd "$TEMPLATE" + printf '_answers_file: .copier-answers.yaml\n\nproject_name:\n type: str\n default: demo\n' > copier.yml + printf 'hello {{ project_name }}\n' > hello.txt.jinja + printf '{{ _copier_answers|to_nice_yaml }}\n' > '{{ _copier_conf.answers_file }}.jinja' + git init -q . + git add -A + git commit -qm "template v1" + git tag v1 + + copier copy --defaults --vcs-ref v1 "$TEMPLATE" "$PROJECT" + cd "$PROJECT" + git init -q . + git add -A + git commit -qm "generated" + + cd "$TEMPLATE" + printf 'goodbye {{ project_name }}\n' > bye.txt.jinja + git add -A + git commit -qm "template v2" + git tag v2 + shell: bash + env: + TEMPLATE: ${{ runner.temp }}/template + PROJECT: ${{ runner.temp }}/project + + - name: Run the update action + uses: ./update + with: + token: ${{ github.token }} + path: ${{ runner.temp }}/project + dry_run: true + + - name: Verify the project was updated in place + run: | + set -eux + test -f "$PROJECT/bye.txt" + grep -q "goodbye demo" "$PROJECT/bye.txt" + git -C "$PROJECT" status --porcelain | grep -q . + shell: bash + env: + PROJECT: ${{ runner.temp }}/project diff --git a/update/action.yml b/update/action.yml index e114412..1aa7471 100644 --- a/update/action.yml +++ b/update/action.yml @@ -21,6 +21,16 @@ inputs: description: "Pull request title (default: 'Update from copier')" required: false default: "Update from copier" + dry_run: + type: boolean + description: "Run the update but do not push a branch or open a pull request" + required: false + default: false + path: + type: string + description: "Directory holding the copier-managed project" + required: false + default: "." runs: @@ -39,12 +49,14 @@ runs: - run: copier update -A -f -a .copier-answers* shell: bash + working-directory: ${{ inputs.path }} - run: | if git status --porcelain -- ':!.copier-answers.yaml' ':!pnpm-lock.yaml' ':!js/pnpm-lock.yaml' ':!Cargo.lock' ':!rust/Cargo.lock' | grep -q .; then echo "COPIER_CHANGED=true" >> "$GITHUB_ENV" fi shell: bash + working-directory: ${{ inputs.path }} - if: env.COPIER_CHANGED == 'true' && hashFiles('pnpm-lock.yaml') != '' uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9 @@ -80,7 +92,7 @@ runs: shell: bash continue-on-error: true - - if: env.COPIER_CHANGED == 'true' + - if: env.COPIER_CHANGED == 'true' && inputs.dry_run != 'true' run: | CURRENT_DATE=`date -u +"%Y-%m-%dT%H-%M-%S"` MESSAGE="${{ inputs.title }} from copier (`date -u +"%Y-%m-%dT%H:%M:%S"`)" @@ -93,5 +105,6 @@ runs: git push origin $BRANCH gh pr create -B ${{ inputs.base }} -H $BRANCH --title "$MESSAGE" --body "" shell: bash + working-directory: ${{ inputs.path }} env: GITHUB_TOKEN: ${{ inputs.token }}