-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (81 loc) · 3.06 KB
/
Copy pathpublish.yml
File metadata and controls
95 lines (81 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Publish to PyPI
on:
push:
branches:
- main
permissions:
contents: read
jobs:
check-version:
name: Check if version changed
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.check.outputs.should_publish }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.12"
- name: Get local version
id: local_version
run: |
VERSION=$(python -c "exec(open('shopify_app/_version.py').read()); print(__version__)")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Local version: $VERSION"
- name: Check if version exists on PyPI
id: check
run: |
VERSION="${{ steps.local_version.outputs.version }}"
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/shopifyapp/$VERSION/json")
if [ "$HTTP_STATUS" = "404" ]; then
echo "Version $VERSION not found on PyPI - will publish"
echo "should_publish=true" >> $GITHUB_OUTPUT
elif [ "$HTTP_STATUS" = "200" ]; then
echo "Version $VERSION already exists on PyPI - skipping publish"
echo "should_publish=false" >> $GITHUB_OUTPUT
else
echo "::error::Unexpected response from PyPI (HTTP $HTTP_STATUS) - failing to be safe"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
build:
name: Build package
needs: check-version
if: needs.check-version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.12"
- name: Install build dependencies
run: python -m pip install --require-hashes -r requirements-dev.txt
- name: Build package
run: python -m build --no-isolation
- name: Upload build artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: dist
path: dist/
publish:
name: Publish to PyPI
needs: [check-version, build]
if: needs.check-version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write # Required for OIDC trusted publishing
environment:
name: pypi
url: https://pypi.org/project/shopifyapp/${{ needs.check-version.outputs.version }}/
steps:
- name: Download build artifacts
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
# No credentials needed - uses OIDC trusted publishing