-
Notifications
You must be signed in to change notification settings - Fork 7
142 lines (123 loc) · 4.5 KB
/
release.yaml
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
name: Release Workflow
run-name: ${{ (github.event.release.prerelease && 'Beta') || 'Prod'}} Release for ${{ github.repository }} - ${{ github.event.release.tag_name }}
on:
release:
# Triggered on Pre-Releases and Releases
types: [released, prereleased]
# Only allow one release at the time
concurrency:
group: deploy-${{ github.repository }}-release-${{ github.event.release.prerelease }}
jobs:
define-environment:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-environment.outputs.version }}
steps:
- uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: audit
- name: Configure Environment
id: get-environment
run: |
wget -O /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
chmod +x /usr/local/bin/semver
if [[ $(semver validate ${{ github.event.release.tag_name }}) == "invalid" ]]; then
echo "::error title=Invalid Release::Release must be tagged with a valid SemVer version"
exit 1
fi
echo "version=$(semver get release ${{ github.event.release.tag_name }})" >> $GITHUB_OUTPUT
build:
name: Build Package
needs: define-environment
uses: ./.github/workflows/build.yaml
secrets: 'inherit'
with:
version: ${{ needs.define-environment.outputs.version }}
environment: ${{ github.event.release.prerelease && 'beta' || 'prod' }}
publish-docker:
name: Publish docker image for ${{ needs.define-environment.outputs.deployment_longname }}
needs: [define-environment, build]
uses: ./.github/workflows/publish-docker.yaml
secrets: 'inherit'
with:
tag: ${{ github.event.release.tag_name }}${{ needs.define-environment.outputs.deployment_environment }}
environment: dockerhub
extra_tag: ${{ github.event.release.prerelease && 'beta' || 'latest' }}
publish-pypi:
name: Publish to PyPi
needs: [define-environment, build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/pantos-${{ github.repository }}/${{ needs.define-environment.outputs.version }}
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: audit
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build
path: dist
- name: Publish package distributions to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
repository-url: 'https://upload.pypi.org/legacy/'
add-assets:
name: Add Assets to the ${{ github.event.release.tag_name }} Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: audit
- uses: actions/download-artifact@v4
with:
name: build
path: release
- name: Upload release assets
uses: svenstaro/upload-release-action@v2
with:
file: "./release/*"
file_glob: true
overwrite: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.release.tag_name }}
- uses: robinraju/[email protected]
name: Download tarball
with:
tag: ${{ github.event.release.tag_name }}
tarBall: true
zipBall: true
fileName: '*'
out-file-path: external-release
preRelease: ${{ github.event.release.prerelease }}
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
- name: List directory
run: |
ls -lha external-release
# Remove all the files in external-release that are also present in release
for file in $(ls release); do
rm -f external-release/$file
done
- uses: sigstore/gh-action-sigstore-python@v3
with:
inputs: external-release/*
- name: Upload signed source code
uses: ncipollo/release-action@v1
with:
artifacts: "./external-release/*"
artifactErrorsFailBuild: true
allowUpdates: true
tag: ${{ github.event.release.tag_name }}
token: ${{ secrets.GITHUB_TOKEN }}