Skip to content

Commit ba67d0a

Browse files
committed
Initial template
0 parents  commit ba67d0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+7161
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @pavelzw @0xbe7a @AdrianFreundQC

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: monthly
7+
groups:
8+
copier-actions:
9+
patterns:
10+
- "*"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Autoupdate
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: 0 6 * * *
6+
7+
jobs:
8+
update:
9+
name: Update ${{ matrix.name }}
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
include:
14+
- script: update_actions
15+
name: gh-actions
16+
steps:
17+
- name: Checkout branch
18+
uses: actions/checkout@v4
19+
- name: Set up Conda env
20+
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822
21+
with:
22+
environment-file: environment.yml
23+
- name: Update ${{ matrix.name }}
24+
run: python -m scripts.${{ matrix.script }}
25+
shell: micromamba-shell {0}
26+
env:
27+
GH_TOKEN: ${{ github.token }}
28+
- uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e
29+
with:
30+
commit-message: Auto-update ${{ matrix.name }}
31+
title: Auto-update ${{ matrix.name }}
32+
body: |
33+
New versions of pinned dependencies in ${{ matrix.name }} were detected.
34+
This PR updates them to the latest version.
35+
branch: update-${{ matrix.name }}
36+
delete-branch: true
37+
- name: Create issue on failure
38+
if: failure()
39+
uses: actions/github-script@v7
40+
with:
41+
script: |
42+
github.rest.issues.listForRepo({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
state: "open",
46+
labels: "[bot] autoupdate"
47+
}).then((issues) => {
48+
if (issues.data.length === 0) {
49+
github.rest.issues.create({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
title: "${{ matrix.name }} update failed",
53+
body: "See https://github.com/quantco/copier-template-python-open-source/actions/runs/${{ github.run_id }} for details.",
54+
labels: ["[bot] autoupdate"]
55+
})
56+
}
57+
});

.github/workflows/ci-copier.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: CI Copier
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
8+
# Automatically stop old builds on the same branch/PR
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
pre-commit-checks:
15+
name: Pre-commit Checks
16+
timeout-minutes: 30
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout branch
20+
uses: actions/checkout@v4
21+
- name: Set up pixi
22+
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
23+
with:
24+
environments: default lint
25+
- name: pre-commit
26+
run: pixi run pre-commit-run --color=always --show-diff-on-failure
27+
28+
pytest:
29+
name: pytest
30+
timeout-minutes: 30
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout branch
34+
uses: actions/checkout@v4
35+
- name: Set up pixi
36+
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
37+
- name: Cache pre-commit envs
38+
uses: actions/cache@v4
39+
with:
40+
path: |
41+
~/.cache/pre-commit
42+
key: project-generation-pre-commit-${{ hashFiles('template/.pre-commit-config.yaml.jinja') }}
43+
- name: Test
44+
run: pixi run test
45+
46+
test-generated-package-ci:
47+
name: Test CI of generated package (minimal-python = ${{ matrix.minimal-python-version }})
48+
timeout-minutes: 30
49+
runs-on: ubuntu-latest
50+
strategy:
51+
matrix:
52+
minimal-python-version: [py38, py310]
53+
54+
steps:
55+
- name: Checkout branch
56+
uses: actions/checkout@v4
57+
with:
58+
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
59+
- name: Set up pixi
60+
uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659
61+
- name: Test generated package CI
62+
run: |
63+
# Name of the generated package.
64+
# Authentication for pushing to $REPO.
65+
AUTH='authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
66+
eval $(ssh-agent)
67+
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
68+
# Set up local Git so that copier can run "git commit".
69+
git config --global user.email "landocalrissian@example.com"
70+
git config --global user.name "Lando Calrissian"
71+
# Generate package with default settings + Windows CI.
72+
copier copy \
73+
--data project_name="Package" \
74+
--data project_short_description="Example Package" \
75+
--data github_user="LandoCalrissian" \
76+
--data project_slug="package" \
77+
--data minimal_python_version="${{ matrix.minimal-python-version }}" \
78+
--defaults \
79+
--trust \
80+
. out
81+
cd out
82+
# Push the generated package's HEAD commit to a `ci/*` branch
83+
cid=$(git rev-parse HEAD)
84+
git push -f "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" $cid:refs/heads/ci/$GITHUB_SHA
85+
# Use the GitHub API to wait for the generated package's CI to complete (success or failure).
86+
# We look for a GitHub Actions run for the HEAD commit ID.
87+
WORKFLOW_URL="$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs?branch=ci/${GITHUB_SHA}&head_sha=${cid}"
88+
echo "Waiting for inner CI to start"
89+
while (( $(curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | length") < 1 )); do
90+
sleep 10
91+
done
92+
echo "Waiting for inner CI to complete"
93+
while curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | .[] | .status" | grep --invert-match completed > /dev/null; do
94+
sleep 10
95+
done
96+
# Fail unless CI was successful.
97+
if curl -Ls --header "$AUTH" "$WORKFLOW_URL" | jq -r ".workflow_runs | .[] | .conclusion" | grep --invert-match success > /dev/null; then
98+
echo "CI pipeline failed"
99+
exit 1
100+
fi
101+
- name: Clean up CI branch
102+
if: always()
103+
run: |
104+
AUTH='authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
105+
eval $(ssh-agent)
106+
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
107+
108+
git push -d "${GITHUB_SERVER_URL/https:\/\//git@}:$GITHUB_REPOSITORY" refs/heads/ci/$GITHUB_SHA
109+
110+
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")
111+
do
112+
curl -Ls --header "$AUTH" --request POST "$GITHUB_API_URL/repos/${GITHUB_REPOSITORY}/actions/runs/$line/cancel" > /dev/null
113+
done

0 commit comments

Comments
 (0)