1
+ name : release
2
+
3
+ on :
4
+ push :
5
+ tags :
6
+ - " [0-9]+.[0-9]+.[0-9]+"
7
+ - " [0-9]+.[0-9]+.[0-9]+a[0-9]+"
8
+ - " [0-9]+.[0-9]+.[0-9]+b[0-9]+"
9
+ - " [0-9]+.[0-9]+.[0-9]+rc[0-9]+"
10
+
11
+ env :
12
+ PACKAGE_NAME : " polarsteps-data-parser"
13
+ OWNER : " niekvleeuwen"
14
+
15
+ jobs :
16
+ details :
17
+ runs-on : ubuntu-latest
18
+ outputs :
19
+ new_version : ${{ steps.release.outputs.new_version }}
20
+ suffix : ${{ steps.release.outputs.suffix }}
21
+ tag_name : ${{ steps.release.outputs.tag_name }}
22
+ steps :
23
+ - uses : actions/checkout@v2
24
+
25
+ - name : Extract tag and Details
26
+ id : release
27
+ run : |
28
+ if [ "${{ github.ref_type }}" = "tag" ]; then
29
+ TAG_NAME=${GITHUB_REF#refs/tags/}
30
+ NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}')
31
+ SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "")
32
+ echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
33
+ echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
34
+ echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
35
+ echo "Version is $NEW_VERSION"
36
+ echo "Suffix is $SUFFIX"
37
+ echo "Tag name is $TAG_NAME"
38
+ else
39
+ echo "No tag found"
40
+ exit 1
41
+ fi
42
+
43
+ check_pypi :
44
+ needs : details
45
+ runs-on : ubuntu-latest
46
+ steps :
47
+ - name : Fetch information from PyPI
48
+ run : |
49
+ response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}")
50
+ latest_previous_version=$(echo $response | jq --raw-output "select(.releases != null) | .releases | keys_unsorted | last")
51
+ if [ -z "$latest_previous_version" ]; then
52
+ echo "Package not found on PyPI."
53
+ latest_previous_version="0.0.0"
54
+ fi
55
+ echo "Latest version on PyPI: $latest_previous_version"
56
+ echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV
57
+
58
+ - name : Compare versions and exit if not newer
59
+ run : |
60
+ NEW_VERSION=${{ needs.details.outputs.new_version }}
61
+ LATEST_VERSION=$latest_previous_version
62
+ if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then
63
+ echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI."
64
+ exit 1
65
+ else
66
+ echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI."
67
+ fi
68
+
69
+ setup_and_build :
70
+ needs : [details, check_pypi]
71
+ runs-on : ubuntu-latest
72
+ steps :
73
+ - uses : actions/checkout@v2
74
+
75
+ - name : Set up Python
76
+ uses : actions/setup-python@v4
77
+ with :
78
+ python-version : " 3.12"
79
+
80
+ - name : Install Poetry
81
+ run : |
82
+ curl -sSL https://install.python-poetry.org | python3 -
83
+ echo "$HOME/.local/bin" >> $GITHUB_PATH
84
+
85
+ - name : Set project version with Poetry
86
+ run : |
87
+ poetry version ${{ needs.details.outputs.new_version }}
88
+
89
+ - name : Install dependencies
90
+ run : poetry install --sync --no-interaction
91
+
92
+ - name : Build source and wheel distribution
93
+ run : |
94
+ poetry build
95
+
96
+ - name : Upload artifacts
97
+ uses : actions/upload-artifact@v3
98
+ with :
99
+ name : dist
100
+ path : dist/
101
+
102
+ pypi_publish :
103
+ name : Upload release to PyPI
104
+ needs : [setup_and_build, details]
105
+ runs-on : ubuntu-latest
106
+ environment :
107
+ name : release
108
+ permissions :
109
+ id-token : write
110
+ steps :
111
+ - name : Download artifacts
112
+ uses : actions/download-artifact@v3
113
+ with :
114
+ name : dist
115
+ path : dist/
116
+
117
+ - name : Publish distribution to PyPI
118
+ uses : pypa/gh-action-pypi-publish@release/v1
119
+
120
+ github_release :
121
+ name : Create GitHub Release
122
+ needs : [setup_and_build, details]
123
+ runs-on : ubuntu-latest
124
+ permissions :
125
+ contents : write
126
+ steps :
127
+ - name : Checkout Code
128
+ uses : actions/checkout@v3
129
+ with :
130
+ fetch-depth : 0
131
+
132
+ - name : Download artifacts
133
+ uses : actions/download-artifact@v3
134
+ with :
135
+ name : dist
136
+ path : dist/
137
+
138
+ - name : Create GitHub Release
139
+ id : create_release
140
+ env :
141
+ GH_TOKEN : ${{ github.token }}
142
+ run : |
143
+ gh release create ${{ needs.details.outputs.tag_name }} dist/* --title ${{ needs.details.outputs.tag_name }} --generate-notes
0 commit comments