-
Notifications
You must be signed in to change notification settings - Fork 28
155 lines (137 loc) · 4.9 KB
/
deploy-stable.yml
File metadata and controls
155 lines (137 loc) · 4.9 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
name: deploy-stable
on:
# Currently this workflow only runs when triggered manually. Perhaps we can set it up to run when a tag is pushed. Or when a release is made. Or that it could create a release, on a release it can create a tag?
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
level:
description: "The level of release to make"
required: true
type: choice
default: "patch"
options:
- "patch"
- "minor"
- "major"
branch:
description: "Use main branch for regular releases, legacy-support for 1.8x fixes."
required: false
type: choice
default: "main"
options:
- "main"
- "legacy-support"
core-repo:
description: "The repository to use for the core commit."
required: false
type: choice
default: "PreTeXtbook/pretext"
options:
- "PreTeXtbook/pretext"
- "oscarlevin/pretext"
jobs:
tests:
name: Run tests
uses: ./.github/workflows/tests.yml
deploy:
needs: tests
name: Deploy to pypi
runs-on: ubuntu-22.04
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
# Sets up python3
- uses: actions/setup-python@v4
with:
python-version: 3.12
# Setup poetry
- name: Install poetry 1.8.4
run: |
python -m ensurepip
python -m pip install --upgrade pip
python -m pip install poetry==1.8.4
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get -y install python3-louis librsvg2-bin libcairo2-dev
- name: Install dependencies
shell: bash
run: poetry install --all-extras
- name: Update version if needed
if: ${{ inputs.level != 'patch' }}
run: poetry version ${{ inputs.level }}
- name: Build package
run: poetry run python scripts/build_package.py ${{ inputs.core-repo }}
- name: Discover current version
run: |
poetry run pretext --version
echo "VERSION=$(poetry run pretext --version)" >> $GITHUB_ENV
- name: Publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
- name: update changelog
run: |
poetry run python scripts/update_changelog.py
- name: Update version for next dev release
run: poetry version patch
- name: setup git config
run: |
# setup the username and email.
git config user.name "${{ github.actor }} via GitHub Actions"
git config user.email "${{ github.actor }}@github_actions.no_reply"
- name: commit version bump via pr
run: |
git checkout -b ${{ env.VERSION }}-deploy
git add CHANGELOG.md
git commit -m "update changelog for release"
git add pyproject.toml
git commit -m "bump version to next patch level for nightly releases"
git add pretext/resources/resource_hash_table.json
git commit --allow-empty -m "commit changes to resource_hash_table.json"
git push -f --set-upstream origin ${{ env.VERSION }}-deploy
gh pr create --fill
# Wait briefly for PR to be fully processed before merging
sleep 5
# Retry merge up to 3 times in case of transient API errors
for attempt in 1 2 3; do
if gh pr merge -s -d -t "Update changelog and bump version to next patch level for nightly releases"; then
echo "PR merged successfully"
break
elif [ $attempt -lt 3 ]; then
echo "Merge attempt $attempt failed, retrying in 10 seconds..."
sleep 10
else
echo "Failed to merge PR after 3 attempts"
exit 1
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.VERSION }}
run: |
gh release create "v$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="v$tag" \
--notes="See the [changelog](CHANGELOG.md) for details."
dispatch:
needs: deploy
strategy:
matrix:
repo: ['pretextbook/pretext-docker', 'pretextbook/html-static']
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.PUSH_CODESPACES }}
repository: ${{ matrix.repo }}
event-type: pretext-publish
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'