|
| 1 | +name: Continuous Delivery |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +jobs: |
| 10 | + # testing: |
| 11 | + # uses: ./.github/workflows/test.yml |
| 12 | + |
| 13 | + semantic-versioning-release: |
| 14 | + name: Upload release to PyPI |
| 15 | + runs-on: ubuntu-latest |
| 16 | + # needs: |
| 17 | + # - testing |
| 18 | + |
| 19 | + concurrency: |
| 20 | + group: ${{ github.workflow }}-release-${{ github.ref_name }} |
| 21 | + cancel-in-progress: false |
| 22 | + environment: |
| 23 | + name: pypi |
| 24 | + url: https://pypi.org/p/PyFracVAL |
| 25 | + permissions: |
| 26 | + id-token: write |
| 27 | + contents: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Setup | Checkout Repository on Release Branch |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + ref: ${{ github.ref_name }} |
| 34 | + fetch-depth: 0 |
| 35 | + |
| 36 | + - name: Setup | Force release branch to be at workflow sha |
| 37 | + run: git reset --hard ${{ github.sha }} |
| 38 | + |
| 39 | + - name: Setup | Install uv |
| 40 | + uses: astral-sh/setup-uv@v4 |
| 41 | + |
| 42 | + - name: Evaluate | Verify upstream has NOT changed |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + set +o pipefail |
| 46 | +
|
| 47 | + UPSTREAM_BRANCH_NAME="$(git status -sb | head -n 1 | cut -d' ' -f2 | grep -E '\.{3}' | cut -d'.' -f4)" |
| 48 | + printf '%s\n' "Upstream branch name: $UPSTREAM_BRANCH_NAME" |
| 49 | +
|
| 50 | + set -o pipefail |
| 51 | +
|
| 52 | + if [ -z "$UPSTREAM_BRANCH_NAME" ]; then |
| 53 | + printf >&2 '%s\n' "::error::Unable to determine upstream branch name!" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + git fetch "${UPSTREAM_BRANCH_NAME%%/*}" |
| 58 | +
|
| 59 | + if ! UPSTREAM_SHA="$(git rev-parse "$UPSTREAM_BRANCH_NAME")"; then |
| 60 | + printf >&2 '%s\n' "::error::Unable to determine upstream branch sha!" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + HEAD_SHA="$(git rev-parse HEAD)" |
| 65 | +
|
| 66 | + if [ "$HEAD_SHA" != "$UPSTREAM_SHA" ]; then |
| 67 | + printf >&2 '%s\n' "[HEAD SHA] $HEAD_SHA != $UPSTREAM_SHA [UPSTREAM SHA]" |
| 68 | + printf >&2 '%s\n' "::error::Upstream has changed, aborting release..." |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + printf '%s\n' "Verified upstream branch has not changed, continuing with release..." |
| 73 | +
|
| 74 | + - name: Action | Semantic Version Release |
| 75 | + id: release |
| 76 | + uses: python-semantic-release/[email protected] |
| 77 | + with: |
| 78 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + git_committer_name: "github-actions" |
| 80 | + git_committer_email: "[email protected]" |
| 81 | + |
| 82 | + - name: Publish | Upload to GitHub Release Assets |
| 83 | + uses: python-semantic-release/[email protected] |
| 84 | + if: steps.release.outputs.released == 'true' |
| 85 | + with: |
| 86 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + tag: ${{ steps.release.outputs.tag }} |
| 88 | + |
| 89 | + - name: Publish | Build and Publish to PyPI |
| 90 | + if: steps.release.outputs.released == 'true' |
| 91 | + run: uv publish |
0 commit comments