-
Notifications
You must be signed in to change notification settings - Fork 52
177 lines (159 loc) · 5.31 KB
/
release-zango.yml
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Publish Zango
on:
pull_request:
types: [closed]
paths:
- 'CHANGELOG.md'
branches:
- main
jobs:
check-publish:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check_publish.outputs.version }}
publish: ${{ steps.check_publish.outputs.publish }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract Latest Tag
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release ls -L 1 --json "tagName" >> info.json
LATEST_TAG=$(cat info.json | jq -r '.[0].tagName')
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Check Publish
id: check_publish
env:
LATEST_TAG: ${{ env.LATEST_TAG }}
run: |
echo "latest_tag=$LATEST_TAG"
CHANGELOG_VERSION=$(grep -m 1 '## \[' CHANGELOG.md | sed 's/.*\[\(.*\)\]/\1/' | grep -oE '([0-9]+\.[0-9]+\.[0-9]+\.?\w*)')
INIT_VERSION=$(grep '__version__' backend/src/zango/__init__.py | sed 's/.*__version__ = "\(.*\)"/\1/'| tail -1)
SETUP_VERSION=$(grep 'PLATFORM_VERSION' backend/setup.py | sed 's/.*PLATFORM_VERSION = "\(.*\)"/\1/'| head -n 1)
if [[ "$CHANGELOG_VERSION" != "$INIT_VERSION" ]] || [[ "$CHANGELOG_VERSION" != "$SETUP_VERSION" ]] || [[ "$LATEST_TAG" == "v$CHANGELOG_VERSION" ]]; then
echo "publish=false" >> $GITHUB_OUTPUT
else
echo "publish=true" >> $GITHUB_OUTPUT
echo "version=$INIT_VERSION" >> $GITHUB_OUTPUT
fi
publish-to-dockerhub:
runs-on: ubuntu-latest
needs: check-publish
if: needs.check-publish.outputs.publish == 'true' && github.event.pull_request.merged == true
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/zango:latest
- name: Build and Push Docker image with tag
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ secrets.DOCKERHUB_USERNAME }}/zango:${{ needs.check-publish.outputs.version }}
build-zango:
name: Build zango
runs-on: ubuntu-latest
if: needs.check-publish.outputs.publish == 'true' && github.event.pull_request.merged == true
needs: check-publish
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: |
python3 -m build backend --outdir dist
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
if: needs.check-publish.outputs.publish == 'true' && github.event.pull_request.merged == true
name: Publish Zango to PyPI
needs:
- build-zango
- check-publish
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/zango
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish Zango to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
github-release:
if: needs.check-publish.outputs.publish == 'true' && github.event.pull_request.merged == true
name: >-
Sign Zango with Sigstore
and upload it to GitHub Release
needs:
- publish-to-pypi
- build-zango
- check-publish
runs-on: ubuntu-latest
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Extract release notes
id: extract-changelog
uses: sean0x42/markdown-extract@v2
with:
file: CHANGELOG.md
pattern: '${{ needs.check-publish.outputs.version }}'
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.check-publish.outputs.version }}
release_name: v${{ needs.check-publish.outputs.version }}
prerelease: false
draft: false
body: ${{ steps.extract-changelog.outputs.markdown }}