Skip to content

Commit 7036487

Browse files
committed
Fix tests and add pixi
1 parent bf6984b commit 7036487

12 files changed

+3462
-118
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# GitHub syntax highlighting
2+
pixi.lock linguist-language=YAML
3+

.github/workflows/bump-versions.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
from pathlib import Path
2222
2323
tools = {}
24-
skip_actions = []
24+
# incompatible with subdirectory actions
25+
skip_actions = ["Quantco/ui-actions/version-metadata"]
2526
2627
for file in Path("template/.github/workflows").glob("*"):
2728
content = file.read_text()

.github/workflows/ci-copier.yml

+5-115
Original file line numberDiff line numberDiff line change
@@ -6,131 +6,21 @@ concurrency:
66
group: ${{ github.workflow }}-${{ github.ref }}
77
cancel-in-progress: true
88

9-
defaults:
10-
run:
11-
shell: bash -el {0}
12-
139
jobs:
1410
linux-unittests:
1511
name: Check project generation
1612
timeout-minutes: 30
1713
runs-on: ubuntu-latest
1814
steps:
19-
- name: Checkout branch
15+
- name: Checkout
2016
uses: actions/checkout@v4
21-
- name: Set up Conda env
22-
uses: mamba-org/setup-micromamba@8767fb704bd78032e9392f0386bf46950bdd1194
23-
with:
24-
environment-file: environment.yml
25-
cache-environment: true
26-
create-args: >-
27-
python=3.11
28-
pytest-md
29-
pytest-emoji
30-
- name: Cache pre-commit envs
31-
uses: actions/cache@v4
3217
with:
33-
path: |
34-
~/.cache/pre-commit
35-
key: project-generation-pre-commit-${{ hashFiles('template/.pre-commit-config.yaml') }}
18+
fetch-depth: 0 # copier doesn't like shallow clones
19+
- name: Set up pixi
20+
uses: prefix-dev/setup-pixi@ca3b9ac762955fad216e3d8e0bbf22087071c89c
3621
- name: Run unittests
3722
uses: quantco/pytest-action@v2
3823
with:
3924
report-title: Check project generation
4025
click-to-expand: false
41-
42-
pre-commit-checks:
43-
name: Pre-commit checks - Python 3.11
44-
timeout-minutes: 30
45-
runs-on: ubuntu-latest
46-
steps:
47-
- name: Checkout branch
48-
uses: actions/checkout@v4
49-
with:
50-
fetch-depth: 0 # Fetching the entire branch history is necessary for the 'pre-commit-insert-license' hook to recognize the actual git lifespan of a file.
51-
- name: Run pre-commit-conda
52-
uses: quantco/pre-commit-conda@v1
53-
with:
54-
python-version: "3.11"
55-
56-
test-generated-package-ci:
57-
name: Test CI of generated package (rattler-build = ${{ matrix.use-rattler-build }}) (mypy = ${{ matrix.use-mypy }})
58-
timeout-minutes: 30
59-
runs-on: ubuntu-latest
60-
concurrency: test-generated-package-ci-${{ github.sha }}-${{ matrix.use-rattler-build }}-${{ matrix.use-mypy }}
61-
strategy:
62-
matrix:
63-
include:
64-
- use-rattler-build: false
65-
use-mypy: true
66-
- use-rattler-build: true
67-
use-mypy: true
68-
- use-rattler-build: true
69-
use-mypy: false
70-
71-
steps:
72-
- name: Checkout branch
73-
uses: actions/checkout@v4
74-
with:
75-
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
76-
ref: ${{ github.head_ref }}
77-
- name: Set up Conda env
78-
uses: mamba-org/setup-micromamba@8767fb704bd78032e9392f0386bf46950bdd1194
79-
with:
80-
environment-file: environment.yml
81-
cache-environment: true
82-
- name: Test generated package CI
83-
run: |
84-
# Name of the generated package.
85-
PKG=quantcore.test-package
86-
# Authentication for pushing to $REPO.
87-
AUTH='authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
88-
eval $(ssh-agent)
89-
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
90-
# Set up local Git so that copier can run "git commit".
91-
git config --global user.email "[email protected]"
92-
git config --global user.name "Forrest Quant"
93-
# Generate package with default settings + Windows CI.
94-
copier copy \
95-
--data project_name="Package" \
96-
--data project_short_description="Example Package" \
97-
--data use_rattler_build="${{ matrix.use-rattler-build }}" \
98-
--data use_mypy="${{ matrix.use-mypy }}" \
99-
--data github_user="ForrestQuant" \
100-
--data project_slug="$PKG" \
101-
--defaults \
102-
--trust \
103-
. out
104-
cd out
105-
# Push the generated package's HEAD commit to a `ci/*` branch
106-
cid=$(git rev-parse HEAD)
107-
git push -f "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" $cid:refs/heads/ci/$GITHUB_SHA-${{ matrix.use-rattler-build }}-${{ matrix.use-mypy }}
108-
# Use the GitHub API to wait for the generated package's CI to complete (success or failure).
109-
# We look for a GitHub Actions run for the HEAD commit ID.
110-
WORKFLOW_URL="$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}-${{ matrix.use-rattler-build }}-${{ matrix.use-mypy }}&head_sha=${cid}"
111-
echo "Waiting for inner CI to start"
112-
while (( $(curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | length") < 1 )); do
113-
sleep 10
114-
done
115-
echo "Waiting for inner CI to complete"
116-
while curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | .[] | .status" | grep --invert-match completed > /dev/null; do
117-
sleep 10
118-
done
119-
# Fail unless CI was successful.
120-
if curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | .[] | .conclusion" | grep --invert-match success > /dev/null; then
121-
echo "CI pipeline failed"
122-
exit 1
123-
fi
124-
- name: Clean up CI branch
125-
if: always()
126-
run: |
127-
AUTH='authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
128-
eval $(ssh-agent)
129-
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
130-
131-
git push -d "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" refs/heads/ci/$GITHUB_SHA-${{ matrix.use-rattler-build }}-${{ matrix.use-mypy }}
132-
133-
for line in $(curl -Ls --header "$AUTH" "$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}-${{ matrix.use-rattler-build }}-${{ matrix.use-mypy }}&head_sha=${cid}" | jq -r ".workflow_runs | .[] | select(.status != \"completed\") | .id")
134-
do
135-
curl -Ls --header "$AUTH" --request POST "$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs/$line/cancel" > /dev/null
136-
done
26+
custom-pytest: pixi run pytest

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# pixi environments
2+
.pixi
3+
4+
__pycache__

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
# copier-template-pre-commit-mirrors
22

33
This is a template for our pre-commit mirrors.
4+
5+
To create a new mirror, you can run the following command
6+
7+
```bash
8+
pixi run generate /path/to/mirror
9+
```

copier.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@ _min_copier_version: '9.1.1'
66
tool:
77
type: str
88
help: What is the name of the tool?
9+
validator: >-
10+
{% if entry == '' %}
11+
Please provide a valid tool name
12+
{% endif %}
913
url:
1014
type: str
1115
help: What is the URL of the tool?
16+
validator: >-
17+
{% if not url.startswith('https://') %}
18+
Please provide a URL
19+
{% endif %}
1220
entry:
1321
type: str
14-
help: What is the pre-commit entry?
22+
help: What is the pre-commit entry (for example `ruff --fix --exit-non-zero-on-fix`)?
23+
validator: >-
24+
{% if entry == '' %}
25+
Please provide an entry
26+
{% endif %}
1527
1628
_tasks:
29+
- sed -i "s/TOOL_VERSION/$(micromamba search -c conda-forge {{ tool }} --json | jq -r '.result.pkgs[0].version')/g" environment.yml
1730
- git init
18-
- gsed -i "s/TOOL_VERSION/$(micromamba search {{ tool }} --json | jq -r '.result.pkgs[0].version')/g" environment.yml
31+
- git branch -M main

0 commit comments

Comments
 (0)