-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (142 loc) · 4.75 KB
/
release.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
name: Publish to PyPI
# Workflow runs prerelease job on every push to main branch
# and a release job on every tag push.
# A publish job is executed on every successful prerelease or release job
# And if publish is successful, the version is also updated in the pyproject.toml file and pushed to main branch
# Workflow does not trigger itself as it only changes pyproject.toml, which is not in paths for this workflow
# The package is distributed as sed-processor
on:
push:
# branches:
# - main
tags:
- '*'
paths:
- specsanalyzer/**/*
- specsscan/**/*
- .github/workflows/release.yml
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
prerelease:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: 3.8
poetry-version: 1.2.2
- name: Change to distribution name in toml file
run: |
cd specsanalyzer
sed -i 's/name = "specsanalyzer"/name = "specsanalyzer"/' pyproject.toml
- name: bump pre-release version
id: version
working-directory: specsanalzer
run: |
VERSION=$(poetry version -s prerelease)
echo "version=$VERSION" >> $GITHUB_OUTPUT
poetry build
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: specsanalzer/dist
- name: Upload pyproject.toml
uses: actions/upload-artifact@v3
with:
name: pyproject
path: specsanalzer/pyproject.toml
release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: 3.8
poetry-version: 1.2.2
- name: Change to distribution name in toml file
run: |
cd specsanalyzer
sed -i 's/name = "specsanalyzer"/name = "specsanalyzer"/' pyproject.toml
- name: Bump release version and build
id: version
working-directory: specsanalyzer
run: |
VERSION=$(echo ${GITHUB_REF#refs/tags/v} | sed 's/-.*//')
echo "version=$VERSION" >> $GITHUB_OUTPUT
poetry version $VERSION
poetry build
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: specsanalyzer/dist
- name: Upload pyproject.toml
uses: actions/upload-artifact@v3
with:
name: pyproject
path: specsanalyzer/pyproject.toml
publish:
needs: [prerelease, release]
if: always() && (needs.prerelease.result == 'success' || needs.release.result == 'success')
runs-on: ubuntu-latest
outputs:
version: ${{ needs.prerelease.outputs.version || needs.release.outputs.version }}
environment:
name: test-pypi
url: https://test-pypi.org/p/specsanalyzer
permissions:
id-token: write
steps:
- name: Download a single artifact
uses: actions/download-artifact@v3
with:
name: dist
- name: Publish package distributions to PyPI Test
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: .
bump-version:
needs: publish
if: always() && (needs.publish.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v3
with:
lfs: true
token: ${{ steps.generate_token.outputs.token }}
- name: Download pyproject.toml
uses: actions/download-artifact@v3
with:
name: pyproject
- name: Commit files
run: |
cd specsanalyzer/
git config --local user.email "bump[bot]@users.noreply.github.com"
git config --local user.name "bump[bot]"
git add $GITHUB_WORKSPACE/pyproject.toml
git commit -m "bump version to ${{ needs.publish.outputs.version }}"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ steps.generate_token.outputs.token }}
branch: main