diff --git a/.github/workflows/ci-copier.yml b/.github/workflows/ci-copier.yml index 7ea8461..6cd15ab 100644 --- a/.github/workflows/ci-copier.yml +++ b/.github/workflows/ci-copier.yml @@ -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: @@ -51,7 +49,6 @@ jobs: strategy: matrix: minimal-python-version: [py38, py310] - steps: - name: Checkout branch uses: actions/checkout@v4 @@ -59,6 +56,8 @@ jobs: 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. @@ -70,7 +69,7 @@ jobs: git config --global user.email "landocalrissian@example.com" 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" \ @@ -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 @@ -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 diff --git a/README.md b/README.md index a7994fb..afc39c2 100644 --- a/README.md +++ b/README.md @@ -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 +pixi exec --spec copier --spec ruamel.yaml -- copier copy --trust https://github.com/quantco/copier-template-python-open-source ``` 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. diff --git a/copier.yml b/copier.yml index 6d42696..7923df0 100644 --- a/copier.yml +++ b/copier.yml @@ -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; diff --git a/pixi.lock b/pixi.lock index b87b88a..2f12643 100644 --- a/pixi.lock +++ b/pixi.lock @@ -26,6 +26,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/funcy-2.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/gh-2.52.0-he0e2781_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/git-2.45.2-pl5321ha099dd3_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/go-yq-4.44.2-h8b461db_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/identify-2.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.0.0-pyha770c72_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/iniconfig-2.0.0-pyhd8ed1ab_0.conda @@ -118,6 +119,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/funcy-2.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/gh-2.52.0-he13f2d6_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/git-2.45.2-pl5321hb0c6a96_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-64/go-yq-4.44.2-hfdf4475_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/identify-2.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.0.0-pyha770c72_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/iniconfig-2.0.0-pyhd8ed1ab_0.conda @@ -204,6 +206,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/funcy-2.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/gh-2.52.0-h163aea0_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/git-2.45.2-pl5321h41514c7_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/go-yq-4.44.2-h99b78c6_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/identify-2.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.0.0-pyha770c72_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/iniconfig-2.0.0-pyhd8ed1ab_0.conda @@ -289,6 +292,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/funcy-2.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/gh-2.52.0-h36e2d1d_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/git-2.45.2-h57928b3_1.conda + - conda: https://conda.anaconda.org/conda-forge/win-64/go-yq-4.44.2-h2466b09_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/identify-2.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-8.0.0-pyha770c72_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/iniconfig-2.0.0-pyhd8ed1ab_0.conda @@ -1327,6 +1331,67 @@ packages: license: GPL-2.0-or-later and LGPL-2.1-or-later size: 11871414 timestamp: 1718524953917 +- kind: conda + name: go-yq + version: 4.44.2 + build: h2466b09_0 + subdir: win-64 + url: https://conda.anaconda.org/conda-forge/win-64/go-yq-4.44.2-h2466b09_0.conda + sha256: 284b26aeef97fea5f8b076f488f1e698c574c74bc92c0f9d694a38b80e9070e2 + md5: e79173b4d4c48166817d9248b09a314d + depends: + - ucrt >=10.0.20348.0 + - vc >=14.2,<15 + - vc14_runtime >=14.29.30139 + license: MIT + license_family: MIT + size: 7330908 + timestamp: 1718519042900 +- kind: conda + name: go-yq + version: 4.44.2 + build: h8b461db_0 + subdir: linux-64 + url: https://conda.anaconda.org/conda-forge/linux-64/go-yq-4.44.2-h8b461db_0.conda + sha256: be8bf02baa3e1185fa160a349375bcd0b43751aff625722d04226969404760cd + md5: d1623ab147bf37c3c083989e1c517a35 + depends: + - __glibc >=2.17 + - libgcc-ng >=12 + license: MIT + license_family: MIT + size: 3468241 + timestamp: 1718518470574 +- kind: conda + name: go-yq + version: 4.44.2 + build: h99b78c6_0 + subdir: osx-arm64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/go-yq-4.44.2-h99b78c6_0.conda + sha256: 1580203042b6c770ef1ce46c23d10ee7136877f8aa5e77a5c3da0014f3776567 + md5: 5107663d414ce947d748d668915b0bd0 + depends: + - __osx >=11.0 + license: MIT + license_family: MIT + size: 3266981 + timestamp: 1718518684882 +- kind: conda + name: go-yq + version: 4.44.2 + build: hfdf4475_0 + subdir: osx-64 + url: https://conda.anaconda.org/conda-forge/osx-64/go-yq-4.44.2-hfdf4475_0.conda + sha256: a61539b12e381a85189714890fabb67ad87f75d07bfd7a6338858f794d8f46c8 + md5: 06f5abffacc647d532cac54532213daf + depends: + - __osx >=10.13 + constrains: + - __osx>=10.12 + license: MIT + license_family: MIT + size: 3510512 + timestamp: 1718518541178 - kind: conda name: icu version: '73.2' diff --git a/pixi.toml b/pixi.toml index 30772cc..20e206d 100644 --- a/pixi.toml +++ b/pixi.toml @@ -13,6 +13,7 @@ pytest = ">=8.2,<9" mypy = "*" pre-commit = "*" gh = "*" +go-yq = "*" [feature.lint.dependencies] pre-commit = "*" diff --git a/template/.github/workflows/{% if add_autobump_workflow %}update-lockfiles.yml{% endif %} b/template/.github/workflows/{% if add_autobump_workflow %}update-lockfiles.yml{% endif %} new file mode 100644 index 0000000..248459e --- /dev/null +++ b/template/.github/workflows/{% if add_autobump_workflow %}update-lockfiles.yml{% endif %} @@ -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 diff --git a/tests/test_template.py b/tests/test_template.py index 06fa9a9..c24684e 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -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"] )