|
1 | 1 | name: Release |
2 | 2 |
|
| 3 | +# based off of https://github.com/astral-sh/ruff/blob/main/.github/workflows/release.yaml |
3 | 4 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - "*.*.*" |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + tag: |
| 8 | + description: "The version to tag (without the leading 'v'). If omitted, will initiate a dry run (no uploads)." |
| 9 | + default: "" |
| 10 | + type: string |
| 11 | + branch: |
| 12 | + description: "The branch from which to release." |
| 13 | + type: string |
| 14 | + prerelease: |
| 15 | + description: "Whether the release is a pre-release." |
| 16 | + default: false |
| 17 | + type: boolean |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 21 | + cancel-in-progress: true |
7 | 22 |
|
8 | 23 | jobs: |
9 | | - release: |
10 | | - name: Release |
| 24 | + validate-tag: |
| 25 | + name: Validate tag |
11 | 26 | runs-on: ubuntu-latest |
| 27 | + # If you don't set an input tag, it's a dry run (no uploads). |
| 28 | + if: ${{ inputs.tag }} |
12 | 29 | steps: |
13 | | - # will use ref/SHA that triggered it |
14 | | - - name: Checkout code |
15 | | - uses: actions/checkout@v3 |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + ref: ${{ inputs.branch }} |
| 33 | + |
| 34 | + - name: Check tag consistency |
| 35 | + run: | |
| 36 | + # Switch to the commit we want to release |
| 37 | + git checkout ${{ inputs.branch }} |
| 38 | + version=$(grep "^version = " pyproject.toml | sed -e 's/version = "\(.*\)"/\1/g') |
| 39 | + if [ "${{ inputs.tag }}" != "${version}" ]; then |
| 40 | + echo "The input tag does not match the version from pyproject.toml:" >&2 |
| 41 | + echo "${{ inputs.tag }}" >&2 |
| 42 | + echo "${version}" >&2 |
| 43 | + exit 1 |
| 44 | + else |
| 45 | + echo "Releasing ${version}" |
| 46 | + fi |
16 | 47 |
|
17 | | - - name: Set up Python 3.10 |
18 | | - uses: actions/setup-python@v4 |
| 48 | + tag-release: |
| 49 | + name: Tag release |
| 50 | + runs-on: ubuntu-latest |
| 51 | + needs: validate-tag |
| 52 | + # If you don't set an input tag, it's a dry run (no uploads). |
| 53 | + if: ${{ inputs.tag }} |
| 54 | + permissions: |
| 55 | + # For git tag |
| 56 | + contents: write |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
19 | 59 | with: |
20 | | - python-version: "3.10" |
| 60 | + ref: ${{ inputs.branch }} |
21 | 61 |
|
22 | | - - name: Install hatch |
| 62 | + - name: git tag |
23 | 63 | run: | |
24 | | - pip install hatch |
| 64 | + git config --global user.email "cergen@berkeley.edu" |
| 65 | + git config --global user.name "popv release" |
| 66 | + git tag -m "${{ inputs.tag }}" "${{ inputs.tag }}" |
| 67 | + # If there is duplicate tag, this will fail. The publish to pypi action will have been a noop (due to skip |
| 68 | + # existing), so we make a non-destructive exit here |
| 69 | + git push --tags |
| 70 | +
|
| 71 | + publish-release: |
| 72 | + name: Publish to GitHub |
| 73 | + runs-on: ubuntu-latest |
| 74 | + needs: tag-release |
| 75 | + # If you don't set an input tag, it's a dry run (no uploads). |
| 76 | + if: ${{ inputs.tag }} |
| 77 | + permissions: |
| 78 | + # For GitHub release publishing |
| 79 | + contents: write |
| 80 | + |
| 81 | + steps: |
| 82 | + - uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + ref: ${{ inputs.branch }} |
| 85 | + |
| 86 | + - uses: softprops/action-gh-release@v2 |
| 87 | + with: |
| 88 | + name: popv ${{ inputs.tag }} |
| 89 | + tag_name: ${{ inputs.tag }} |
| 90 | + generate_release_notes: false |
| 91 | + body_path: .github/workflows/release_notes.md |
| 92 | + prerelease: ${{ inputs.prerelease }} |
| 93 | + target_commitish: ${{ inputs.branch }} |
| 94 | + |
| 95 | + upload-release: |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: tag-release |
| 98 | + environment: |
| 99 | + name: pypi |
| 100 | + url: https://pypi.org/p/popv |
| 101 | + permissions: |
| 102 | + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing |
| 103 | + # If you don't set an input tag, it's a dry run (no uploads). |
| 104 | + if: ${{ inputs.tag }} |
| 105 | + |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + filter: blob:none |
| 110 | + fetch-depth: 0 |
| 111 | + ref: ${{ inputs.branch }} |
| 112 | + |
| 113 | + - uses: actions/setup-python@v4 |
| 114 | + with: |
| 115 | + python-version: "3.11" |
| 116 | + |
| 117 | + - run: pip install build |
| 118 | + |
| 119 | + - run: python -m build |
| 120 | + |
| 121 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 122 | + |
| 123 | + build-image: |
| 124 | + runs-on: ubuntu-latest |
| 125 | + needs: tag-release |
| 126 | + |
| 127 | + permissions: |
| 128 | + contents: read |
| 129 | + packages: write |
| 130 | + |
| 131 | + strategy: |
| 132 | + fail-fast: false |
| 133 | + matrix: |
| 134 | + dependencies: [""] |
| 135 | + # If you don't set an input tag, it's a dry run (no uploads). |
| 136 | + if: ${{ inputs.tag }} |
| 137 | + |
| 138 | + steps: |
| 139 | + - uses: actions/checkout@v4 |
| 140 | + with: |
| 141 | + filter: blob:none |
| 142 | + fetch-depth: 0 |
| 143 | + ref: ${{ inputs.branch }} |
25 | 144 |
|
26 | | - - name: Build project for distribution |
27 | | - run: hatch build |
| 145 | + - uses: docker/setup-buildx-action@v3 |
| 146 | + |
| 147 | + - uses: docker/login-action@v3 |
| 148 | + with: |
| 149 | + registry: ghcr.io |
| 150 | + username: ${{ github.actor }} |
| 151 | + password: ${{ secrets.GITHUB_TOKEN }} |
28 | 152 |
|
29 | | - - name: Publish a Python distribution to PyPI |
30 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
| 153 | + - uses: docker/build-push-action@v5 |
31 | 154 | with: |
32 | | - password: ${{ secrets.PYPI_TOKEN }} |
| 155 | + context: . |
| 156 | + file: ./Dockerfile |
| 157 | + push: true |
| 158 | + cache-from: type=registry,ref=ghcr.io/yoseflab/popv:buildcache |
| 159 | + cache-to: type=inline,ref=ghcr.io/yoseflab/popv:buildcache |
| 160 | + target: build |
| 161 | + tags: ghcr.io/yoseflab/popv:py3.11-cu12-${{ inputs.tag }}-${{ matrix.dependencies }} |
| 162 | + build-args: | |
| 163 | + DEPENDENCIES=${{ matrix.dependencies }} |
0 commit comments