|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: "Existing git tag to release (for example v2026.04.14)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: release-${{ github.event.inputs.tag || github.ref_name }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + validate: |
| 23 | + name: Validate release tag |
| 24 | + runs-on: ubuntu-latest |
| 25 | + outputs: |
| 26 | + tag: ${{ steps.meta.outputs.tag }} |
| 27 | + version: ${{ steps.meta.outputs.version }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Check out repository |
| 31 | + uses: actions/checkout@v5 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Resolve release metadata |
| 36 | + id: meta |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then |
| 40 | + TAG="${{ github.event.inputs.tag }}" |
| 41 | + git fetch --tags origin "${TAG}:${TAG}" |
| 42 | + else |
| 43 | + TAG="${GITHUB_REF_NAME}" |
| 44 | + fi |
| 45 | +
|
| 46 | + if [[ ! "${TAG}" =~ ^v[0-9]{4}\.[0-9]{2}\.[0-9]{2}(\.[0-9]+)?$ ]]; then |
| 47 | + echo "Tag ${TAG} does not match vYYYY.MM.DD or vYYYY.MM.DD.N" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + VERSION="$(python - <<'PY' |
| 52 | +from pathlib import Path |
| 53 | +import re |
| 54 | + |
| 55 | +text = Path("src/octopal/_version.py").read_text(encoding="utf-8") |
| 56 | +match = re.search(r'__version__\s*=\s*"([^"]+)"', text) |
| 57 | +if not match: |
| 58 | + raise SystemExit("Could not find __version__ in src/octopal/_version.py") |
| 59 | +print(match.group(1)) |
| 60 | +PY |
| 61 | +)" |
| 62 | + |
| 63 | + EXPECTED_VERSION="${TAG#v}" |
| 64 | + if [[ "${VERSION}" != "${EXPECTED_VERSION}" ]]; then |
| 65 | + echo "Version mismatch: tag=${EXPECTED_VERSION}, file=${VERSION}" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + |
| 69 | + echo "tag=${TAG}" >> "${GITHUB_OUTPUT}" |
| 70 | + echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" |
| 71 | + |
| 72 | + test: |
| 73 | + name: Run release checks |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: validate |
| 76 | + |
| 77 | + steps: |
| 78 | + - name: Check out repository |
| 79 | + uses: actions/checkout@v5 |
| 80 | + with: |
| 81 | + ref: ${{ needs.validate.outputs.tag }} |
| 82 | + |
| 83 | + - name: Set up Python |
| 84 | + uses: actions/setup-python@v6 |
| 85 | + with: |
| 86 | + python-version: "3.12" |
| 87 | + |
| 88 | + - name: Set up uv |
| 89 | + uses: astral-sh/setup-uv@v7 |
| 90 | + |
| 91 | + - name: Sync dependencies |
| 92 | + run: uv sync --extra dev |
| 93 | + |
| 94 | + - name: Run test suite |
| 95 | + run: uv run pytest |
| 96 | + |
| 97 | + publish: |
| 98 | + name: Publish GitHub release |
| 99 | + runs-on: ubuntu-latest |
| 100 | + needs: |
| 101 | + - validate |
| 102 | + - test |
| 103 | + |
| 104 | + steps: |
| 105 | + - name: Create GitHub release |
| 106 | + env: |
| 107 | + GH_TOKEN: ${{ github.token }} |
| 108 | + TAG: ${{ needs.validate.outputs.tag }} |
| 109 | + VERSION: ${{ needs.validate.outputs.version }} |
| 110 | + shell: bash |
| 111 | + run: | |
| 112 | + if gh release view "${TAG}" >/dev/null 2>&1; then |
| 113 | + echo "Release ${TAG} already exists; skipping." |
| 114 | + exit 0 |
| 115 | + fi |
| 116 | +
|
| 117 | + gh release create "${TAG}" \ |
| 118 | + --verify-tag \ |
| 119 | + --title "Octopal ${VERSION}" \ |
| 120 | + --generate-notes |
0 commit comments