From 0afd4b9257745be416584163cc55727faab5b09e Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Fri, 29 Dec 2023 19:06:10 -0800 Subject: [PATCH 1/2] select commit in workflow --- .github/workflows/python_release.yml | 50 ++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python_release.yml b/.github/workflows/python_release.yml index 6fece41..3793f09 100644 --- a/.github/workflows/python_release.yml +++ b/.github/workflows/python_release.yml @@ -5,7 +5,7 @@ # name: python-release -# section adapted from https://github.com/astral-sh/ruff/blob/main/.github/workflows/release.yaml +# adapted from https://github.com/astral-sh/ruff/blob/main/.github/workflows/release.yaml on: workflow_dispatch: inputs: @@ -36,6 +36,8 @@ jobs: target: [x86_64] steps: - uses: actions/checkout@v3 + with: + ref: ${{ inputs.sha }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -61,6 +63,8 @@ jobs: target: [x64] steps: - uses: actions/checkout@v3 + with: + ref: ${{ inputs.sha }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -86,6 +90,8 @@ jobs: target: [x86_64, aarch64] steps: - uses: actions/checkout@v3 + with: + ref: ${{ inputs.sha }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -106,6 +112,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + ref: ${{ inputs.sha }} - name: Build sdist uses: PyO3/maturin-action@v1 with: @@ -117,11 +125,49 @@ jobs: name: wheels path: dist + # adapted from https://github.com/astral-sh/ruff/blob/main/.github/workflows/release.yaml + validate-tag: + name: Validate tag + runs-on: ubuntu-latest + # If you don't set an input tag, it's a dry run (no uploads). + if: ${{ inputs.tag }} + steps: + - uses: actions/checkout@v4 + with: + ref: main # We checkout the main branch to check for the commit + - 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 tag consistency + run: | + # Switch to the commit we want to release + git checkout ${{ inputs.sha }} + version=$(grep "version = " pyproject.toml | sed -e 's/version = "\(.*\)"/\1/g') + if [ "${{ inputs.tag }}" != "${version}" ]; then + echo "The input tag does not match the version from pyproject.toml:" >&2 + echo "${{ inputs.tag }}" >&2 + echo "${version}" >&2 + exit 1 + else + echo "Releasing ${version}" + fi + release: name: Release runs-on: ubuntu-latest if: "startsWith(github.ref, 'refs/tags/')" - needs: [linux, windows, macos, sdist] + needs: + - linux + - windows + - macos + - sdist + - validate-tag environment: name: pypi url: https://pypi.org/p/cryo-python From b99385ca6d3741f71097bcc3a862f78d4fc8caa8 Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Fri, 29 Dec 2023 19:38:28 -0800 Subject: [PATCH 2/2] simplify workflow inputs --- .github/workflows/python_release.yml | 43 ++++------------------------ 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/.github/workflows/python_release.yml b/.github/workflows/python_release.yml index 3793f09..79c1e08 100644 --- a/.github/workflows/python_release.yml +++ b/.github/workflows/python_release.yml @@ -9,13 +9,14 @@ name: python-release on: workflow_dispatch: inputs: - tag: - description: "The version to tag, without the leading 'v'. If omitted, will initiate a dry run (no uploads)." - type: string sha: 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 + release: + description: 'Set to true to run the release on pypi, dry run otherwise' + required: true + default: 'false' pull_request: paths: # When we change pyproject.toml, we want to ensure that the maturin builds still work @@ -125,49 +126,15 @@ jobs: name: wheels path: dist - # adapted from https://github.com/astral-sh/ruff/blob/main/.github/workflows/release.yaml - validate-tag: - name: Validate tag - runs-on: ubuntu-latest - # If you don't set an input tag, it's a dry run (no uploads). - if: ${{ inputs.tag }} - steps: - - uses: actions/checkout@v4 - with: - ref: main # We checkout the main branch to check for the commit - - 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 tag consistency - run: | - # Switch to the commit we want to release - git checkout ${{ inputs.sha }} - version=$(grep "version = " pyproject.toml | sed -e 's/version = "\(.*\)"/\1/g') - if [ "${{ inputs.tag }}" != "${version}" ]; then - echo "The input tag does not match the version from pyproject.toml:" >&2 - echo "${{ inputs.tag }}" >&2 - echo "${version}" >&2 - exit 1 - else - echo "Releasing ${version}" - fi - release: name: Release runs-on: ubuntu-latest - if: "startsWith(github.ref, 'refs/tags/')" + if: "github.event.inputs.release == 'true'" needs: - linux - windows - macos - sdist - - validate-tag environment: name: pypi url: https://pypi.org/p/cryo-python