Skip to content

Commit 2dbef25

Browse files
authored
Fix tests (#2)
* Fix tests * fix * on merge group
1 parent c03dc86 commit 2dbef25

File tree

7 files changed

+130
-12
lines changed

7 files changed

+130
-12
lines changed

.github/workflows/ci-copier.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: CI Copier
22
on:
33
pull_request:
4-
push:
5-
branches:
6-
- main
4+
merge_group:
75

86
# Automatically stop old builds on the same branch/PR
97
concurrency:
@@ -51,14 +49,15 @@ jobs:
5149
strategy:
5250
matrix:
5351
minimal-python-version: [py38, py310]
54-
5552
steps:
5653
- name: Checkout branch
5754
uses: actions/checkout@v4
5855
with:
5956
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
6057
- name: Set up pixi
6158
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
59+
with:
60+
activate-environment: true
6261
- name: Test generated package CI
6362
run: |
6463
# Name of the generated package.
@@ -70,7 +69,7 @@ jobs:
7069
git config --global user.email "landocalrissian@example.com"
7170
git config --global user.name "Lando Calrissian"
7271
# Generate package with default settings + Windows CI.
73-
pixi run copier copy \
72+
copier copy \
7473
--data project_name="Package" \
7574
--data project_short_description="Example Package" \
7675
--data github_user="LandoCalrissian" \
@@ -80,12 +79,17 @@ jobs:
8079
--trust \
8180
. out
8281
cd out
82+
# Replace actions trigger with on: [push]
83+
yq eval '.on = ["push"]' -i .github/workflows/ci.yml
84+
yq eval '.on = ["push"]' -i .github/workflows/build.yml
85+
git add .github/workflows/ci.yml .github/workflows/build.yml
86+
git commit -m "Replace actions trigger with on: [push]"
8387
# Push the generated package's HEAD commit to a `ci/*` branch
8488
cid=$(git rev-parse HEAD)
85-
git push -f "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" $cid:refs/heads/ci/$GITHUB_SHA
89+
git push -f "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" $cid:refs/heads/ci/${GITHUB_SHA}-${{ matrix.minimal-python-version }}
8690
# Use the GitHub API to wait for the generated package's CI to complete (success or failure).
8791
# We look for a GitHub Actions run for the HEAD commit ID.
88-
WORKFLOW_URL="$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}&head_sha=${cid}"
92+
WORKFLOW_URL="$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}-${{ matrix.minimal-python-version }}&head_sha=${cid}"
8993
echo "Waiting for inner CI to start"
9094
while (( $(curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | length") < 1 )); do
9195
sleep 10
@@ -106,9 +110,9 @@ jobs:
106110
eval $(ssh-agent)
107111
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
108112
109-
git push -d "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" refs/heads/ci/$GITHUB_SHA
113+
git push -d "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" refs/heads/ci/$GITHUB_SHA-${{ matrix.minimal-python-version }}
110114
111-
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")
115+
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")
112116
do
113117
curl -Ls --header "$AUTH" --request POST "$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs/$line/cancel" > /dev/null
114118
done

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ For documentation on pixi see [here](https://pixi.sh).
66
## Usage
77

88
```bash
9-
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>
9+
pixi exec --spec copier --spec ruamel.yaml -- copier copy --trust https://github.com/quantco/copier-template-python-open-source <destination-path>
1010
```
1111

1212
To update to a newer template version:
1313

1414
```bash
15-
pixi exec --spec copier --spec ruamel.yaml --spec ruamel.yaml.jinja2 -- copier update --defaults --trust
15+
pixi exec --spec copier --spec ruamel.yaml -- copier update --defaults --trust
1616
```
1717

1818
Note that copier will show `Conflict` for files that have manual changes.

copier.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ minimal_python_version_sortable:
5858
use_devcontainer:
5959
type: bool
6060
help: Should this project use a devcontainer for development?
61-
default: no
61+
default: false
62+
63+
add_autobump_workflow:
64+
type: bool
65+
help: Do you want to add a GitHub Workflow to automatically bump `pixi.lock`?
66+
default: true
6267

6368
_tasks:
6469
- '"{{ _copier_python }}" -I -c "import sys; sys.path.insert(0, \"{{ _copier_conf.src_path }}\"); import runpy;

pixi.lock

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pytest = ">=8.2,<9"
1313
mypy = "*"
1414
pre-commit = "*"
1515
gh = "*"
16+
go-yq = "*"
1617

1718
[feature.lint.dependencies]
1819
pre-commit = "*"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Update lockfiles
2+
permissions:
3+
contents: write
4+
pull-requests: write
5+
6+
on:
7+
workflow_dispatch:
8+
schedule:
9+
- cron: 0 5 1 * *
10+
11+
jobs:
12+
pixi-update:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up pixi
17+
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
18+
with:
19+
run-install: false
20+
- name: Update lockfiles
21+
run: |
22+
pixi global install pixi-diff-to-markdown
23+
pixi update --json --no-install | pixi-diff-to-markdown >> diff.md
24+
- name: Create pull request
25+
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c
26+
with:
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
commit-message: Update pixi lockfile
29+
title: Update pixi lockfile
30+
body-path: diff.md
31+
branch: update-pixi
32+
base: main
33+
labels: pixi
34+
delete-branch: true
35+
add-paths: pixi.lock

tests/test_template.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ def test_devcontainer(generate_project, use_devcontainer):
4545
assert path.exists() == use_devcontainer
4646

4747

48+
@pytest.mark.parametrize("add_autobump_workflow", [True, False])
49+
def test_add_autobump_workflow(generate_project, add_autobump_workflow):
50+
path = generate_project({"add_autobump_workflow": add_autobump_workflow})
51+
assert (
52+
path / ".github" / "workflows" / "update-lockfiles.yml"
53+
).exists() == add_autobump_workflow
54+
55+
4856
@pytest.mark.parametrize(
4957
"minimal_python_version", ["py38", "py39", "py310", "py311", "py312"]
5058
)

0 commit comments

Comments
 (0)