|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'New version number (e.g. 6.3.0)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +jobs: |
| 12 | + validate: |
| 13 | + name: Validate version |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + version: ${{ steps.check.outputs.version }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - name: Check version is valid and greater than current |
| 20 | + id: check |
| 21 | + run: | |
| 22 | + NEW="${{ inputs.version }}" |
| 23 | +
|
| 24 | + # Must match semver X.Y.Z |
| 25 | + if ! echo "$NEW" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
| 26 | + echo "::error::Version '$NEW' is not valid semver (expected X.Y.Z)" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +
|
| 30 | + CURRENT=$(grep -E '^version\s*=\s*"[0-9]+' pyproject.toml | head -n1 \ |
| 31 | + | sed -E 's/.*version\s*=\s*"([^"]+)".*/\1/') |
| 32 | +
|
| 33 | + echo "Current version: $CURRENT" |
| 34 | + echo "Requested version: $NEW" |
| 35 | +
|
| 36 | + version_key() { |
| 37 | + echo "$1" | awk -F. '{ printf "%05d%05d%05d", $1, $2, $3 }' |
| 38 | + } |
| 39 | +
|
| 40 | + if [ "$(version_key "$NEW")" -le "$(version_key "$CURRENT")" ]; then |
| 41 | + echo "::error::New version ($NEW) must be greater than current version ($CURRENT)" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + echo "version=$NEW" >> "$GITHUB_OUTPUT" |
| 46 | +
|
| 47 | + test: |
| 48 | + name: Test (Python ${{ matrix.python-version }}) |
| 49 | + needs: validate |
| 50 | + runs-on: ubuntu-latest |
| 51 | + strategy: |
| 52 | + fail-fast: true |
| 53 | + matrix: |
| 54 | + python-version: ["3.11", "3.12", "3.13", "3.14"] |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + - name: Set up Python ${{ matrix.python-version }} |
| 58 | + uses: actions/setup-python@v5 |
| 59 | + with: |
| 60 | + python-version: ${{ matrix.python-version }} |
| 61 | + cache: 'pip' |
| 62 | + - name: Install dependencies |
| 63 | + run: | |
| 64 | + python -m pip install --upgrade pip |
| 65 | + python -m pip install flake8 |
| 66 | + pip install . .[dev] |
| 67 | + - name: Lint with flake8 |
| 68 | + run: | |
| 69 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 70 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 71 | + - name: Check typing with mypy |
| 72 | + run: mypy src/ynca --check-untyped-defs |
| 73 | + - name: Test with pytest |
| 74 | + run: pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=ynca --cov-report=xml --cov-report=html |
| 75 | + |
| 76 | + release: |
| 77 | + name: Bump, tag and create draft release |
| 78 | + needs: test |
| 79 | + runs-on: ubuntu-latest |
| 80 | + permissions: |
| 81 | + contents: write |
| 82 | + steps: |
| 83 | + - name: Generate GitHub App token |
| 84 | + id: app-token |
| 85 | + uses: actions/create-github-app-token@v1 |
| 86 | + with: |
| 87 | + app-id: ${{ secrets.GH_APP_ID }} |
| 88 | + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} |
| 89 | + |
| 90 | + - uses: actions/checkout@v4 |
| 91 | + with: |
| 92 | + token: ${{ steps.app-token.outputs.token }} |
| 93 | + ref: master |
| 94 | + |
| 95 | + - name: Bump version in pyproject.toml |
| 96 | + run: | |
| 97 | + NEW="${{ needs.validate.outputs.version }}" |
| 98 | + awk -v newver="$NEW" ' |
| 99 | + BEGIN{inproj=0;done=0} |
| 100 | + /^\[project\]/{inproj=1} |
| 101 | + inproj && !done && /version\s*=/{sub(/version\s*=\s*"[^"]+"/, "version = \"" newver "\""); done=1} |
| 102 | + {print} |
| 103 | + ' pyproject.toml > pyproject.toml.tmp && mv pyproject.toml.tmp pyproject.toml |
| 104 | +
|
| 105 | + - name: Commit, tag and push |
| 106 | + run: | |
| 107 | + NEW="${{ needs.validate.outputs.version }}" |
| 108 | + git config user.name "github-actions[bot]" |
| 109 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 110 | + git add pyproject.toml |
| 111 | + git commit -m "Bump ynca version to $NEW" |
| 112 | + git tag -a "v$NEW" -m "Version $NEW" |
| 113 | + git push --follow-tags |
| 114 | +
|
| 115 | + - name: Create draft release |
| 116 | + env: |
| 117 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 118 | + run: | |
| 119 | + NEW="${{ needs.validate.outputs.version }}" |
| 120 | + gh release create "v$NEW" \ |
| 121 | + --draft \ |
| 122 | + --generate-notes \ |
| 123 | + --title "v$NEW" |
0 commit comments