-
Notifications
You must be signed in to change notification settings - Fork 39
174 lines (153 loc) · 5.07 KB
/
pypi-publish.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
name: Publish Python Package
on:
workflow_dispatch:
inputs:
publish_release:
description: 'Create Production Release'
required: true
type: boolean
skip_test_pypi:
description: "Skip publishing to test PyPI"
required: false
type: boolean
default: "false"
jobs:
publish:
environment: release
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
outputs:
pkg_version: ${{ steps.semver.outputs.next }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Next Version
if: ${{ inputs.publish_release }}
id: semver
uses: ietf-tools/semver-action@v1
with:
patchList: fix, bugfix, perf, refactor, test, tests, chore, revert
token: ${{ github.token }}
branch: main
- name: Set Next Version Env Var
if: ${{ inputs.publish_release }}
env:
NEXT_VERSION: ${{ steps.semver.outputs.next }}
run: |
echo "NEXT_VERSION=$next" >> $GITHUB_ENV
- name: Create Draft Release
uses: ncipollo/release-action@v1
if: ${{ inputs.publish_release }}
with:
prerelease: true
draft: false
commit: ${{ github.sha }}
tag: ${{ env.NEXT_VERSION }}
name: ${{ env.NEXT_VERSION }}
body: '*pending*'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set Build Variables
run: |
if [[ $NEXT_VERSION ]]; then
echo "Using AUTO SEMVER mode: $NEXT_VERSION"
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
echo "PKG_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=${NEXT_VERSION#?}" >> $GITHUB_ENV
elif [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
echo "Using TAG mode: $GITHUB_REF_NAME"
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
echo "PKG_VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
else
echo "Using TEST mode: v3.0.0-dev.$GITHUB_RUN_NUMBER"
echo "SHOULD_DEPLOY=false" >> $GITHUB_ENV
echo "PKG_VERSION=v3.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=3.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
fi
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Python dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip setuptools wheel twine build
sudo apt update
sudo apt install -y twine
- name: Build Python package
run: |
source venv/bin/activate
echo "Using version $PKG_VERSION_STRICT"
sed -i -r -e "s/^__version__ += '.*'$/__version__ = '$PKG_VERSION_STRICT'/" xml2rfc/__init__.py
python -m build --sdist
- name: Update CHANGELOG
id: changelog
uses: Requarks/changelog-action@v1
if: env.SHOULD_DEPLOY == 'true'
with:
token: ${{ github.token }}
tag: ${{ env.PKG_VERSION }}
excludeTypes: ''
- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v5
if: env.SHOULD_DEPLOY == 'true'
with:
branch: main
commit_message: 'docs: update CHANGELOG.md + py file versions for ${{ env.PKG_VERSION }} [skip ci]'
file_pattern: CHANGELOG.md setup.cfg xml2rfc/__init__.py
- name: Create Release
uses: ncipollo/release-action@v1
if: env.SHOULD_DEPLOY == 'true'
with:
allowUpdates: true
draft: false
tag: ${{ env.PKG_VERSION }}
name: ${{ env.PKG_VERSION }}
body: ${{ steps.changelog.outputs.changes }}
artifacts: "dist/**"
token: ${{ secrets.GITHUB_TOKEN }}
makeLatest: true
- name: Publish to Test PyPI
if: ${{ !inputs.skip_test_pypi }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Publish to PyPI
if: env.SHOULD_DEPLOY == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: false
build-base:
runs-on: ubuntu-latest
if: ${{ inputs.publish_release }}
needs: [publish]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Build & Push
uses: docker/build-push-action@v6
with:
context: .
file: docker/base.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/ietf-tools/xml2rfc-base:latest