Skip to content

Commit 52e08e2

Browse files
committed
Replace action with contained script to get enhanced behaviour
1 parent d78940f commit 52e08e2

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

.github/workflows/pipeline.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,31 @@ jobs:
4848
- build_test
4949
runs-on: ubuntu-latest
5050
outputs:
51-
should_release: ${{ steps.whether_to_release.outputs.should_release}}
51+
should_release_pypi: ${{ steps.whether_to_release.outputs.should_release_pypi}}
52+
should_release_test_pypi: ${{ steps.whether_to_release.outputs.should_release_pypi_test}}
5253
permissions:
5354
id-token: write # IMPORTANT: this permission is required to write to github envs
5455
steps:
5556
- uses: actions/checkout@v4
5657
with:
5758
fetch-depth: 0
58-
- name: Check whether to release
59-
uses: MathieuMoalic/action-python-package-new-version@v1.0.5
59+
- name: Check whether to release on pypi.org
60+
run: |
61+
./version_check.sh
62+
- name: Check whether to release on test.pypi.org
63+
run: |
64+
export INDEX=test.pypi.org
65+
./version_check.sh
66+
- name: Assign whether to release to output
67+
id: whether_to_release_pypi
68+
run: echo "should_release_pypi=${{ env.PUBLISHING_pypi_org }}" >> "$GITHUB_OUTPUT"
6069
- name: Assign whether to release to output
61-
id: whether_to_release
62-
run: echo "should_release=${{ env.PUBLISHING }}" >> "$GITHUB_OUTPUT"
70+
id: whether_to_release_test_pypi
71+
run: echo "should_release_test_pypi=${{ env.PUBLISHING_test_pypi_org }}" >> "$GITHUB_OUTPUT"
6372
release:
6473
name: Release NMSpy wheels and source build to PyPI
6574
# Only run this job if we merge into master, we need to do a release, and we don't specifically have some tag to skip publishing to pypi.
66-
if: ${{ github.ref == 'refs/heads/master' && needs.release_check.outputs.should_release == 'true' && !startsWith(github.event.head_commit.message, '[skip pypi]') }}
75+
if: ${{ github.ref == 'refs/heads/master' && needs.release_check.outputs.should_release_pypi == 'true' && !startsWith(github.event.head_commit.message, '[skip pypi]') }}
6776
needs:
6877
- build_test
6978
- release_check
@@ -87,7 +96,7 @@ jobs:
8796
test-release:
8897
name: Release NMSpy wheels and source build to test-PyPI
8998
# Only run this job if we merge into master and if we need to do a release.
90-
if: ${{ github.ref == 'refs/heads/master' && needs.release_check.outputs.should_release == 'true' }}
99+
if: ${{ github.ref == 'refs/heads/master' && needs.release_check.outputs.should_release_test_pypi == 'true' }}
91100
needs:
92101
- build_test
93102
- release_check

version_check.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# This script is copied directly from https://github.com/MathieuMoalic/action-python-package-new-version/blob/main/entrypoint.sh
4+
# This is just until there is extra functionality as part of that repo to allow specifying a different index.
5+
6+
# Check if pyproject.toml exists
7+
PYPROJECT_FILE=pyproject.toml
8+
9+
if [ ! -f "$PYPROJECT_FILE" ]; then
10+
error_exit "$PYPROJECT_FILE does not exist."
11+
fi
12+
13+
# Step 1: Get version from pyproject.toml
14+
VERSION=$(awk -F'=' '/^version/ {gsub(/[" ]/, "", $2); print $2}' "$PYPROJECT_FILE")
15+
if [ -z "$VERSION" ]; then
16+
error_exit "Unable to extract version from $PYPROJECT_FILE"
17+
fi
18+
echo "Version is $VERSION"
19+
20+
INDEX="${PYPI_INDEX:-pypi.org}"
21+
22+
# Step 2: Get package name from pyproject.toml
23+
PACKAGE_NAME=$(awk -F'=' '/^name/ {gsub(/[" ]/, "", $2); print $2}' "$PYPROJECT_FILE")
24+
if [ -z "$PACKAGE_NAME" ]; then
25+
error_exit "Unable to extract package name from $PYPROJECT_FILE"
26+
fi
27+
echo "PACKAGE_NAME is $PACKAGE_NAME"
28+
29+
# Step 3: Get latest release version from PyPI
30+
PUBLISHED_VERSIONS=$(curl -s "https://$INDEX/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys | .[]')
31+
32+
if [ -z "$PUBLISHED_VERSIONS" ]; then
33+
error_exit "Unable to retrieve published version from PyPI for $PACKAGE_NAME"
34+
fi
35+
echo "Published PyPI versions are $PUBLISHED_VERSIONS"
36+
37+
# Step 4: Check if current version is in the list of published versions
38+
PUBLISHING="true"
39+
for ver in $PUBLISHED_VERSIONS; do
40+
if [ "$ver" == "$VERSION" ]; then
41+
PUBLISHING="false"
42+
break
43+
fi
44+
done
45+
46+
echo "PUBLISHING is $PUBLISHING"
47+
echo "PUBLISHING=$PUBLISHING" >> $GITHUB_ENV
48+
echo "PUBLISHING_${INDEX/./_}=$PUBLISHING" >> $GITHUB_ENV
49+
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV

0 commit comments

Comments
 (0)