Skip to content

Commit 7a042d6

Browse files
authored
chore(template): accept new copier update (#42)
Co-authored-by: wpk-nist-gov <5348008+wpk-nist-gov@users.noreply.github.com>
1 parent 6e650a4 commit 7a042d6

14 files changed

Lines changed: 644 additions & 290 deletions

File tree

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
2-
_commit: v0.7.0-130-gde18aa4
2+
_commit: v0.8.0-6-g056c2e6
33
_src_path: https://github.com/usnistgov/cookiecutter-nist-python.git
44
command_line_interface: typer
55
conda_channel: conda-forge

.github/actions/setup-cached-uv-and-python/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description:
33
Composite action to do 'actions/setup-python' and 'hynek/setup-cached-uv'
44
inputs:
55
# actions/setup-python
6-
76
python-version:
87
description: "Version to pass to actions/setup-python"
98
python-version-file:
@@ -25,7 +24,7 @@ outputs:
2524
value: ${{ steps.setup-python.outputs.cache-hit }}
2625
python-path:
2726
description: "The absolute path to the Python or PyPy executable."
28-
value: ${{ steps.setup-python.outputs.pytyhon-path }}
27+
value: ${{ steps.setup-python.outputs.python-path }}
2928

3029
runs:
3130
using: composite

.github/workflows/ci.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ on:
33
push:
44
branches: [main]
55
pull_request:
6+
types:
7+
- opened
8+
- synchronize
9+
- reopened
10+
- ready_for_review
611
workflow_dispatch:
712

813
concurrency:
@@ -13,6 +18,7 @@ env:
1318
FORCE_COLOR: "3"
1419
UVX_CONSTRAINT: requirements/lock/uvx-tools.txt
1520
UVX_COMMAND: uvx -crequirements/lock/uvx-tools.txt
21+
NOX_COMMAND: uvx -crequirements/lock/uvx-tools.txt nox
1622
EXTRA_PYTHON_VERSIONS: "pypy-3.11"
1723

1824
permissions: {}
@@ -24,6 +30,12 @@ jobs:
2430
outputs:
2531
should_skip: ${{ steps.skip_check.outputs.should_skip }}
2632
steps:
33+
- name: Don't run CI on draft PR
34+
if:
35+
github.event_name == 'pull_request' && github.event.pull_request.draft
36+
== true
37+
run: exit 1
38+
2739
- id: skip_check
2840
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5.3.1
2941
with:
@@ -69,7 +81,6 @@ jobs:
6981
print("{minmax_default_python_versions=}")
7082
print("{all_python_version=}")
7183
72-
7384
with open(os.getenv("GITHUB_OUTPUT"), "a") as f:
7485
f.write(f"{default_python_version=:s}\n")
7586
f.write(f"{min_python_version=:s}\n")
@@ -153,6 +164,9 @@ jobs:
153164
matrix:
154165
os:
155166
- ubuntu-latest
167+
# - windows-latest
168+
session:
169+
- typecheck
156170
steps:
157171
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
158172
with:
@@ -162,14 +176,16 @@ jobs:
162176
python-version-file: ".python-version"
163177
cache-dependency-path: uv.lock
164178
- name: Get python version
179+
id: python_version
165180
run: |
166181
python_version=$(cat .python-version)
167-
echo "python_version=${python_version}" >> "$GITHUB_ENV"
182+
echo "python_version=${python_version}" >> "$GITHUB_OUTPUT"
168183
shell: bash
169184
- name: typecheck
170185
env:
171-
python_version: ${{ env.python_version }}
172-
run: $UVX_COMMAND nox -s typecheck-"$python_version"
186+
python_version: ${{ steps.python_version.outputs.python_version }}
187+
session: ${{ matrix.session }}
188+
run: $NOX_COMMAND -s "${session}-${python_version}"
173189
shell: bash
174190

175191
test:
@@ -188,10 +204,13 @@ jobs:
188204
${{
189205
fromJson(needs.build-package.outputs.minmax-default-python-versions)
190206
}}
207+
session:
208+
- test
191209
include:
192210
- os: windows-latest
193211
python-version:
194212
${{ needs.build-package.outputs.default-python-version }}
213+
session: test
195214
steps:
196215
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
197216
with:
@@ -208,14 +227,19 @@ jobs:
208227
- name: Test with nox
209228
env:
210229
python_version: ${{ matrix.python-version }}
211-
run: >-
212-
$UVX_COMMAND nox -s test-"$python_version" -- ++installpkg dist/*.whl
213-
shell: bash
230+
options: "++installpkg dist/*.whl"
231+
session: ${{ matrix.session }}
232+
run: |
233+
# shellcheck disable=SC2086
234+
$NOX_COMMAND -s "${session}-${python_version}" -- $options
235+
shell: bash -euxo pipefail {0}
214236

215237
- name: Upload coverage data
216238
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
217239
with:
218-
name: coverage-data-${{ matrix.os }}-${{ matrix.python-version }}
240+
name:
241+
coverage-data-${{ matrix.os }}-${{ matrix.python-version }}-${{
242+
matrix.session }}
219243
path: .nox/test-*/tmp/.coverage*
220244
include-hidden-files: true
221245
if-no-files-found: ignore
@@ -247,12 +271,12 @@ jobs:
247271
cache-dependency-path: requirements/lock/uvx-tools.txt
248272
- name: Run coverage
249273
run: |
250-
$UVX_COMMAND nox -s coverage -- ++coverage combine html markdown
274+
$NOX_COMMAND -s coverage -- ++coverage combine html markdown
251275
cat coverage.md
252276
cat coverage.md >> "$GITHUB_STEP_SUMMARY"
253277
254278
# fail if under 100%
255-
$UVX_COMMAND nox -s coverage -- ++coverage report ++coverage-options --fail-under=100
279+
$NOX_COMMAND -s coverage -- ++coverage report ++coverage-options --fail-under=100
256280
shell: bash
257281
- name: Upload HTML report if check failed.
258282
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0

.github/workflows/release-auto.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Create github release
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
# for debugging
13+
# info:
14+
# if: github.event.pull_request.merged == true
15+
# runs-on: ubuntu-latest
16+
# permissions: {}
17+
# steps:
18+
# - name: PR info
19+
# env:
20+
# RELEASE_COMMIT: ${{ github.event.pull_request.merge_commit_sha }}
21+
# RELEASE_BRANCH: ${{ github.head_ref }}
22+
# OWNER: ${{ github.repository_owner }}
23+
# RELEASE: ${{ format('{0}', startsWith(github.head_ref, 'release/')) }}
24+
# run: |
25+
# echo "RELEASE_COMMIT - $RELEASE_COMMIT"
26+
# echo "RELEASE_BRANCH - $RELEASE_BRANCH"
27+
# echo "OWNER - $OWNER"
28+
# echo "RELEASE - $RELEASE"
29+
30+
create-release:
31+
name: Create release
32+
if:
33+
# prettier-ignore
34+
github.event.pull_request.merged == true && github.repository_owner == 'usnistgov' && startsWith(github.head_ref, 'release/')
35+
runs-on: ubuntu-latest
36+
environment:
37+
name: pull-request
38+
permissions:
39+
contents: write
40+
steps:
41+
- name: PR info
42+
env:
43+
RELEASE_COMMIT: ${{ github.event.pull_request.merge_commit_sha }}
44+
RELEASE_BRANCH: ${{ github.head_ref }}
45+
OWNER: ${{ github.repository_owner }}
46+
RELEASE: ${{ format('{0}', startsWith(github.head_ref, 'release/')) }}
47+
run: |
48+
echo "RELEASE_COMMIT - $RELEASE_COMMIT"
49+
echo "RELEASE_BRANCH - $RELEASE_BRANCH"
50+
echo "OWNER - $OWNER"
51+
echo "RELEASE - $RELEASE"
52+
53+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
54+
with:
55+
persist-credentials: false
56+
sparse-checkout: |
57+
pyproject.toml
58+
sparse-checkout-cone-mode: false
59+
60+
- name: Setup python
61+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
62+
with:
63+
python-version: ">=3.11"
64+
65+
- name: Get version
66+
id: version
67+
shell: python
68+
run: |
69+
import os
70+
import tomllib
71+
from pathlib import Path
72+
73+
version = tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"]
74+
tag = f"v{version}"
75+
76+
print("{tag=:s}")
77+
78+
with open(os.getenv("GITHUB_OUTPUT"), "a") as f:
79+
f.write(f"{tag=:s}\n")
80+
81+
- name: Create pull request
82+
env:
83+
GH_TOKEN: ${{ secrets.PAT }}
84+
RELEASE_COMMIT: ${{ github.event.pull_request.merge_commit_sha }}
85+
TAG: ${{ steps.version.outputs.tag }}
86+
run: |
87+
gh release create "$TAG" --generate-notes --target "$RELEASE_COMMIT"
Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
name: Copier update repository
1+
name: Update repo with copier
22
on:
33
schedule:
44
- cron: "0 2 * * 1" # Every Monday at 2am
55
workflow_dispatch:
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
711
permissions:
812
contents: write
913
pull-requests: write
@@ -47,33 +51,53 @@ jobs:
4751
- name: Copier update
4852
continue-on-error: false
4953
id: check
54+
env:
55+
commit_message_in: ${{ matrix.commit-message }}
5056
run: |
51-
CHANGES=0
57+
changed='false'
58+
conflict_message=''
59+
commit_message="$commit_message_in"
60+
5261
if [ -f .copier-answers.yml ]; then
5362
copier update ${{ env.COPIER_OPTIONS }}
5463
if ! git diff --quiet -- .copier-answers.yml; then
55-
CHANGES=1
64+
changed='true'
5665
fi
5766
else
5867
echo "No .copier-answers.yml file"
68+
exit 1
5969
fi
60-
echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT"
6170
62-
- name: Git config
63-
if: steps.check.outputs.has_changes == '1'
64-
run: |
65-
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
66-
git config --global user.name "github-actions[bot]"
67-
git restore --staged .
71+
# determine if have any merge conflicts
72+
if [ "$changed" = "true" ] && ! git merge --no-commit --no-ff; then
73+
conflict_message="Resolve conflicts."
74+
commit_message="$commit_message [skip ci]"
75+
fi
76+
77+
echo "changed=$changed" >> "$GITHUB_OUTPUT"
78+
echo "conflict_message=$conflict_message" >> "$GITHUB_OUTPUT"
79+
echo "commit_message=$commit_message" >> "$GITHUB_OUTPUT"
80+
81+
echo "files_changed<<EOF" >> "$GITHUB_OUTPUT"
82+
git status --short | sort >> "$GITHUB_OUTPUT"
83+
echo "EOF" >> "$GITHUB_OUTPUT"
84+
85+
# git config
86+
if [ "$changed" = "true" ]; then
87+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
88+
git config --global user.name "github-actions[bot]"
89+
git restore --staged .
90+
fi
91+
shell: bash -euxo pipefail {0}
6892

6993
- name: Create pull request
70-
if: steps.check.outputs.has_changes == '1'
94+
if: steps.check.outputs.changed == 'true'
7195
id: cpr
7296
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
7397
with:
7498
token: ${{ secrets.PAT }}
7599
add-paths: ${{ matrix.add-paths }}
76-
commit-message: ${{ matrix.commit-message }}
100+
commit-message: ${{ steps.check.outputs.commit_message }}
77101
title: ${{ matrix.title }}
78102
labels: |
79103
internal
@@ -82,7 +106,10 @@ jobs:
82106
delete-branch: true
83107
# branch-suffix: timestamp # If want commit per run (instead of per workflow)
84108
body: |
85-
This is an autogenerated PR. ${{ matrix.body }}
109+
This is an autogenerated PR. ${{ matrix.body }} ${{ steps.check.outputs.conflict_message }}
110+
111+
Files changed (`git status --short`):
112+
${{ steps.check.outputs.files_changed }}
86113
87114
[copier](https://github.com/copier-org/copier) has detected updates from the Cookiecutter repository.
88115

0 commit comments

Comments
 (0)