Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
75 changes: 75 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion update/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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"`)"
Expand All @@ -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 }}