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
22 changes: 13 additions & 9 deletions .github/workflows/ci-copier.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: CI Copier
on:
pull_request:
push:
branches:
- main
merge_group:

# Automatically stop old builds on the same branch/PR
concurrency:
Expand Down Expand Up @@ -51,14 +49,15 @@ jobs:
strategy:
matrix:
minimal-python-version: [py38, py310]

steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Set up pixi
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
with:
activate-environment: true
- name: Test generated package CI
run: |
# Name of the generated package.
Expand All @@ -70,7 +69,7 @@ jobs:
git config --global user.email "[email protected]"
git config --global user.name "Lando Calrissian"
# Generate package with default settings + Windows CI.
pixi run copier copy \
copier copy \
--data project_name="Package" \
--data project_short_description="Example Package" \
--data github_user="LandoCalrissian" \
Expand All @@ -80,12 +79,17 @@ jobs:
--trust \
. out
cd out
# Replace actions trigger with on: [push]
yq eval '.on = ["push"]' -i .github/workflows/ci.yml
yq eval '.on = ["push"]' -i .github/workflows/build.yml
git add .github/workflows/ci.yml .github/workflows/build.yml
git commit -m "Replace actions trigger with on: [push]"
# Push the generated package's HEAD commit to a `ci/*` branch
cid=$(git rev-parse HEAD)
git push -f "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" $cid:refs/heads/ci/$GITHUB_SHA
git push -f "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" $cid:refs/heads/ci/${GITHUB_SHA}-${{ matrix.minimal-python-version }}
# Use the GitHub API to wait for the generated package's CI to complete (success or failure).
# We look for a GitHub Actions run for the HEAD commit ID.
WORKFLOW_URL="$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}&head_sha=${cid}"
WORKFLOW_URL="$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}-${{ matrix.minimal-python-version }}&head_sha=${cid}"
echo "Waiting for inner CI to start"
while (( $(curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | length") < 1 )); do
sleep 10
Expand All @@ -106,9 +110,9 @@ jobs:
eval $(ssh-agent)
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"

git push -d "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" refs/heads/ci/$GITHUB_SHA
git push -d "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" refs/heads/ci/$GITHUB_SHA-${{ matrix.minimal-python-version }}

for line in $(curl -Ls --header "$AUTH" "$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}&head_sha=${cid}" | jq -r ".workflow_runs | .[] | select(.status != \"completed\") | .id")
for line in $(curl -Ls --header "$AUTH" "$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}-${{ matrix.minimal-python-version }}&head_sha=${cid}" | jq -r ".workflow_runs | .[] | select(.status != \"completed\") | .id")
do
curl -Ls --header "$AUTH" --request POST "$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs/$line/cancel" > /dev/null
done
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ For documentation on pixi see [here](https://pixi.sh).
## Usage

```bash
pixi exec --spec copier --spec ruamel.yaml --spec ruamel.yaml.jinja2 -- copier copy --trust https://github.com/quantco/copier-template-python-open-source <destination-path>
pixi exec --spec copier --spec ruamel.yaml -- copier copy --trust https://github.com/quantco/copier-template-python-open-source <destination-path>
```

To update to a newer template version:

```bash
pixi exec --spec copier --spec ruamel.yaml --spec ruamel.yaml.jinja2 -- copier update --defaults --trust
pixi exec --spec copier --spec ruamel.yaml -- copier update --defaults --trust
```

Note that copier will show `Conflict` for files that have manual changes.
Expand Down
7 changes: 6 additions & 1 deletion copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ minimal_python_version_sortable:
use_devcontainer:
type: bool
help: Should this project use a devcontainer for development?
default: no
default: false

add_autobump_workflow:
type: bool
help: Do you want to add a GitHub Workflow to automatically bump `pixi.lock`?
default: true

_tasks:
- '"{{ _copier_python }}" -I -c "import sys; sys.path.insert(0, \"{{ _copier_conf.src_path }}\"); import runpy;
Expand Down
65 changes: 65 additions & 0 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pytest = ">=8.2,<9"
mypy = "*"
pre-commit = "*"
gh = "*"
go-yq = "*"

[feature.lint.dependencies]
pre-commit = "*"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Update lockfiles
permissions:
contents: write
pull-requests: write

on:
workflow_dispatch:
schedule:
- cron: 0 5 1 * *

jobs:
pixi-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up pixi
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
with:
run-install: false
- name: Update lockfiles
run: |
pixi global install pixi-diff-to-markdown
pixi update --json --no-install | pixi-diff-to-markdown >> diff.md
- name: Create pull request
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update pixi lockfile
title: Update pixi lockfile
body-path: diff.md
branch: update-pixi
base: main
labels: pixi
delete-branch: true
add-paths: pixi.lock
8 changes: 8 additions & 0 deletions tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def test_devcontainer(generate_project, use_devcontainer):
assert path.exists() == use_devcontainer


@pytest.mark.parametrize("add_autobump_workflow", [True, False])
def test_add_autobump_workflow(generate_project, add_autobump_workflow):
path = generate_project({"add_autobump_workflow": add_autobump_workflow})
assert (
path / ".github" / "workflows" / "update-lockfiles.yml"
).exists() == add_autobump_workflow


@pytest.mark.parametrize(
"minimal_python_version", ["py38", "py39", "py310", "py311", "py312"]
)
Expand Down