-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (186 loc) · 7.02 KB
/
commit.yml
File metadata and controls
213 lines (186 loc) · 7.02 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Process Commit
on:
push:
branches:
- "**"
tags:
- "*"
workflow_dispatch:
inputs:
create-release:
description: 'Create a release?'
required: true
default: false
type: boolean
defaults:
run:
shell: bash
jobs:
build-package:
name: Build Python Package
permissions:
contents: read
uses: ./.github/workflows/build-python-package.yml
get-changelog:
name: Generate Info & Changelog
runs-on: ubuntu-latest
permissions:
contents: read
# Start if run from tags or commit message contains [ci release]
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') || contains(github.event.head_commit.message, '[ci release]')
outputs:
name: ${{ steps.get-info.outputs.name }}
type: ${{ steps.get-info.outputs.type }}
hash: ${{ steps.get-info.outputs.hash }}
version: ${{ steps.get-info.outputs.version }}
app-version: ${{ steps.get-info.outputs.app-version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Configure Python environment
uses: ./.github/actions/prepare-python-env
- name: Get info
id: get-info
run: |
uv run autohack --version
VERSION=$(uv run autohack --version)
if [ "${{ startsWith(github.ref, 'refs/tags') }}" = "true" ]; then
echo "name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
if [ "${{ contains(github.ref_name, '.dev') }}" = "true" ]; then
echo "type=Pre-release" >> $GITHUB_OUTPUT
else
echo "type=Release" >> $GITHUB_OUTPUT
fi
else
echo "name=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "type=Commit" >> $GITHUB_OUTPUT
fi
echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Convert version like 1.1.0.dev5 to 1.1.0 for executable
APP_VERSION=$(echo $VERSION | awk -F. '{print $1"."$2"."$3}')
if [ -z "$APP_VERSION" ] || [ "$APP_VERSION" = ".." ]; then
APP_VERSION="0.0.0"
fi
echo "app-version=$APP_VERSION" >> $GITHUB_OUTPUT
- name: Generate complete changelog
run: |
chmod +x ./scripts/generate_changelog.sh
./scripts/generate_changelog.sh \
"${{ steps.get-info.outputs.type }}" \
"${{ steps.get-info.outputs.name }}" \
"${{ steps.get-info.outputs.version }}" \
"changelog.md"
- name: Upload changelog
uses: actions/upload-artifact@v7
with:
name: changelog
path: changelog.md
build-executables:
name: Build Executables
needs: [build-package, get-changelog]
uses: ./.github/workflows/build-executables.yml
with:
app-version: ${{ needs.get-changelog.outputs.app-version }}
release-name: ${{ needs.get-changelog.outputs.name }}
commit-hash: ${{ needs.get-changelog.outputs.hash }}
publish-release:
name: Publish Release & Packages
needs: [build-package, get-changelog, build-executables]
runs-on: ubuntu-latest
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.create-release == 'true') || startsWith(github.ref, 'refs/tags/') || contains(github.event.head_commit.message, '[ci release]')
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Configure Python environment
uses: ./.github/actions/prepare-python-env
- name: Download changelog
uses: actions/download-artifact@v8
with:
name: changelog
- name: Download Python artifacts
uses: actions/download-artifact@v8
with:
name: python-dist
path: dist/
- name: Download executable artifacts
uses: actions/download-artifact@v8
with:
pattern: executable-*
merge-multiple: true
- name: Read changelog for release
id: read-changelog
run: |
{
echo 'changelog<<EOF'
cat changelog.md
echo EOF
} >> $GITHUB_OUTPUT
- name: Check if release exists
id: check-release
run: |
if gh release view ${{ needs.get-changelog.outputs.name }} > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
if: steps.check-release.outputs.exists == 'false'
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.get-changelog.outputs.name }}
release_name: ${{ needs.get-changelog.outputs.name }}
body: ${{ steps.read-changelog.outputs.changelog }}
draft: false
prerelease: ${{ needs.get-changelog.outputs.type != 'Release' }}
- name: Update existing release
if: steps.check-release.outputs.exists == 'true'
run: |
# Update the existing release with new changelog
gh release edit ${{ needs.get-changelog.outputs.name }} \
--notes "${{ steps.read-changelog.outputs.changelog }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Release Assets
run: |
# Upload Python packages
for file in dist/*; do
# Check if file already exists in release
if ! gh release view ${{ needs.get-changelog.outputs.name }} --json assets --jq '.assets[].name' | grep -q "$(basename "$file")"; then
gh release upload ${{ needs.get-changelog.outputs.name }} "$file"
else
echo "File $(basename "$file") already exists in release, skipping..."
fi
done
# Upload executable packages
for file in autohack-*-*-*-*.zip; do
# Check if file already exists in release
if ! gh release view ${{ needs.get-changelog.outputs.name }} --json assets --jq '.assets[].name' | grep -q "$(basename "$file")"; then
gh release upload ${{ needs.get-changelog.outputs.name}} "$file"
else
echo "File $(basename "$file") already exists in release, skipping..."
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to TestPyPI
if: startsWith(github.ref, 'refs/tags/')
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TESTPYPI_API_TOKEN }}
run: |
uv run twine upload --repository testpypi dist/*
- name: Publish to PyPI
if: ${{ needs.get-changelog.outputs.type == 'Release' }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
uv run twine upload dist/*