|
6 | 6 | - "v?[0-9]+.[0-9]+.[0-9]+**" |
7 | 7 | workflow_dispatch: |
8 | 8 |
|
9 | | -# Use "trusted publishing", see https://docs.pypi.org/trusted-publishers/ |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +env: |
| 13 | + ref_name: ${{ github.ref_name }} |
| 14 | + |
10 | 15 | jobs: |
| 16 | + # Use "trusted publishing", see https://docs.pypi.org/trusted-publishers/ |
11 | 17 | release: |
12 | 18 | name: Upload release to PyPI |
13 | 19 | runs-on: ubuntu-latest |
|
30 | 36 | run: uv build |
31 | 37 | - name: Publish package distributions to PyPI |
32 | 38 | uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 |
| 39 | + |
| 40 | + is-prerelease: |
| 41 | + name: Check if this is a pre-release |
| 42 | + runs-on: ubuntu-slim |
| 43 | + outputs: |
| 44 | + is_prerelease: ${{ steps.check_prerelease.outputs.is_prerelease }} |
| 45 | + steps: |
| 46 | + - name: Check if this is a pre-release |
| 47 | + id: check_prerelease |
| 48 | + run: | |
| 49 | + PRE=$(echo "$ref_name" | sed -E 's/^v[0-9]+\.[0-9]+\.[0-9]+(.+?)$/\1/' | wc -w) |
| 50 | + if [ $PRE = 0 ] ; then |
| 51 | + PRE=false |
| 52 | + else |
| 53 | + PRE=true |
| 54 | + fi |
| 55 | + echo "is_prerelease=$PRE" | tee $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + generate-test-data: |
| 58 | + name: Generate test files for backwards compatibility testing |
| 59 | + needs: is-prerelease |
| 60 | + if: ${{ needs.is-prerelease.outputs.is_prerelease == 'false' && github.event_name == 'push' && github.event.created && github.ref_type == 'tag' }} |
| 61 | + runs-on: ubuntu-slim |
| 62 | + env: |
| 63 | + data_path: ./tests/data/archives/${{ github.ref_name }} |
| 64 | + default_branch: ${{ github.event.repository.default_branch }} |
| 65 | + permissions: |
| 66 | + contents: write |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 69 | + with: |
| 70 | + filter: blob:none |
| 71 | + fetch-depth: 0 |
| 72 | + persist-credentials: true |
| 73 | + - name: Install uv |
| 74 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 75 | + with: |
| 76 | + enable-cache: false |
| 77 | + - name: Get environment |
| 78 | + # get the test environment with the oldest Python |
| 79 | + id: get-env |
| 80 | + run: | |
| 81 | + ENV=$(uvx hatch env show --json | jq -r '[to_entries[] | select(.key | startswith("hatch-test") and (contains("pre") | not))] |
| 82 | + | sort_by(.value.python)[0].key') |
| 83 | + echo "hatch_env=${ENV}" | tee $GITHUB_ENV |
| 84 | + - name: create hatch environment |
| 85 | + run: uvx hatch env create "$hatch_env" |
| 86 | + - name: generate output directory |
| 87 | + run: mkdir -p "$data_path" |
| 88 | + - name: generate files |
| 89 | + working-directory: ${{ env.data_path }} |
| 90 | + run: | |
| 91 | + uvx hatch run "$hatch_env":../../../../src/mudata/tests/reference.py |
| 92 | + uvx hatch run "$hatch_env":sh -c "uv pip freeze | uv pip compile - -o pylock.toml" |
| 93 | + - name: configure git |
| 94 | + run: | |
| 95 | + git config user.name github-actions |
| 96 | + git config user.email github-actions@github.com |
| 97 | + BRANCH=$(git branch --show-current) |
| 98 | + if [ ! "$BRANCH" ] ; then |
| 99 | + BRANCH=$(git branch -a --contains "$ref_name" | tail -n 1 | sed 's/^\s*remotes\/origin\///') |
| 100 | + fi |
| 101 | + echo branch=${BRANCH} | tee $GITHUB_ENV |
| 102 | + - name: commit and push |
| 103 | + if: ${{ env.branch != '' }} |
| 104 | + working-directory: ${{ env.data_path }} |
| 105 | + run: | |
| 106 | + git checkout "$branch" |
| 107 | + git add . |
| 108 | + git commit -m "add backwards compat test files for $ref_name" |
| 109 | + git push |
| 110 | + if [ "$branch" != "$default_branch" ] ; then |
| 111 | + git checkout "$default_branch" |
| 112 | + git pull |
| 113 | + git cherry-pick -x "$branch" |
| 114 | + git push |
| 115 | + fi |
| 116 | + - name: commit and push |
| 117 | + if: ${{ env.branch == '' }} |
| 118 | + working-directory: ${{ env.data_path }} |
| 119 | + run: | |
| 120 | + git checkout "$default_branch" |
| 121 | + git pull |
| 122 | + git add . |
| 123 | + git commit -m "add backwards compat test files for $ref_name" |
| 124 | + git push |
0 commit comments