From 1373e1c39540e5e8e4d748df01b9984c278d5b48 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 13 Sep 2023 14:59:41 -0500 Subject: [PATCH] Update release workflow to checkout the given sha (#7279) --- .github/workflows/release.yaml | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 34d71b63e0..b8976da26e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,12 +7,15 @@ on: description: "The version to tag, without the leading 'v'. If omitted, will initiate a dry run (no uploads)." type: string sha: - description: "Optionally, the full sha of the commit to be released" + description: "The full sha of the commit to be released. If omitted, the latest commit on the default branch will be used." + default: "" type: string pull_request: paths: # When we change pyproject.toml, we want to ensure that the maturin builds still work - pyproject.toml + # And when we change this workflow itself... + - .github/workflows/release.yaml concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -31,6 +34,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -57,6 +62,8 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -95,6 +102,8 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -141,6 +150,8 @@ jobs: arch: x64 steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -187,6 +198,8 @@ jobs: - i686-unknown-linux-gnu steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -244,6 +257,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -297,6 +312,8 @@ jobs: - i686-unknown-linux-musl steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -351,6 +368,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} @@ -399,6 +418,8 @@ jobs: if: ${{ inputs.tag }} steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - name: Check tag consistency run: | version=$(grep "version = " pyproject.toml | sed -e 's/version = "\(.*\)"/\1/g') @@ -410,6 +431,15 @@ jobs: else echo "Releasing ${version}" fi + - name: Check main branch + if: ${{ inputs.sha }} + run: | + # Fetch the main branch since a shallow checkout is used by default + git fetch origin main --unshallow + if ! git branch --contains ${{ inputs.sha }} | grep -E '(^|\s)main$'; then + echo "The specified sha is not on the main branch" >&2 + exit 1 + fi - name: Check SHA consistency if: ${{ inputs.sha }} run: | @@ -465,6 +495,8 @@ jobs: contents: write steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.sha }} - name: git tag run: | git config user.email "hey@astral.sh"