-
Notifications
You must be signed in to change notification settings - Fork 44
188 lines (157 loc) · 6.69 KB
/
cd_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
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
name: Publish and Deploy
on:
release:
types:
- published
env:
GIT_USER_NAME: OPTIMADE Developers
GIT_USER_EMAIL: "[email protected]"
DEFAULT_RELEASE_BRANCH: "main"
jobs:
release:
name: Release OPTIMADE Python tools
runs-on: ubuntu-latest
if: github.repository == 'Materials-Consortia/optimade-python-tools' && startsWith(github.ref, 'refs/tags/v')
outputs:
publish_branch: ${{ steps.save_branch.outputs.publish_branch }}
steps:
- name: Get triggering branch
uses: octokit/[email protected]
id: get_release_branch
with:
route: GET /repos/{owner}/{repo}/releases/tags/${{ github.ref_name }}
# Note, the following inputs might give warnings that they are not valid.
# This is due to the flexible nature of the `octokit/request-action`.
# Fore more information see: https://github.com/octokit/request-action/tree/v2.x?tab=readme-ov-file#warnings
owner: Materials-Consortia
repo: optimade-python-tools
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save branch name
id: save_branch
run: |
echo 'publish_branch=${{ fromJson(steps.get_release_branch.outputs.data).target_commitish }}' >> $GITHUB_OUTPUT
- name: Checkout publish branch
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
ref: ${{ steps.save_branch.outputs.publish_branch }}
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install -r requirements.txt -r requirements-dev.txt -r requirements-client.txt -r requirements-http-client.txt -r requirements-docs.txt
pip install -e .[all]
- name: Setup changelog configuration
id: changelog_config
run: |
echo "project=$(echo $GITHUB_REPOSITORY | cut -d/ -f2- )" >> $GITHUB_OUTPUT
echo "exclude_labels=duplicate,question,invalid,wontfix,dependency_updates,skip_changelog" >> $GITHUB_OUTPUT
# For the release-specific changelog
echo "output_file=release_changelog.md" >> $GITHUB_OUTPUT
- name: Update changelog
uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2
with:
args: --user "${{ github.repository_owner }}" --project "${{ steps.changelog_config.outputs.project }}" --token "${{ secrets.RELEASE_PAT_BOT }}" --release-branch "${{ steps.save_branch.outputs.publish_branch }}" --exclude-labels "${{ steps.changelog_config.outputs.exclude_labels }}"
- name: Update API Reference docs and version - Commit changes and update tag
run: .github/utils/update_docs.sh
- name: Update triggering branch
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.RELEASE_PAT_BOT }}
branch: ${{ steps.save_branch.outputs.publish_branch }}
unprotect_reviews: true
sleep: 15
force: true
tags: true
- name: Get previous version
id: get_previous_version
run: echo "previous_version=$(git tag -l --sort -version:refname | sed -n 2p)" >> $GITHUB_OUTPUT
- name: Create release-specific changelog
uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2
with:
args: --user "${{ github.repository_owner }}" --project "${{ steps.changelog_config.outputs.project }}" --token "${{ secrets.RELEASE_PAT_BOT }}" --release-branch "${{ steps.save_branch.outputs.publish_branch }}" --since-tag "${{ steps.get_previous_version.outputs.previous_version }}" --output "${{ steps.changelog_config.outputs.output_file }}" --usernames-as-github-logins --exclude-labels "${{ steps.changelog_config.outputs.exclude_labels }}"
- name: Append changelog to release body
run: |
gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} --jq '.body' > release_body.md
cat ${{ steps.changelog_config.outputs.output_file }} >> release_body.md
gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} -X PATCH -F body='@release_body.md'
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PAT_BOT }}
publish-to-pypi:
name: Publish to PyPI
needs: release
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/optimade
permissions:
id-token: write # Important for Trusted Publishing on PyPI
steps:
- name: Install prerequisites
run: python -m pip install build
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
ref: ${{ needs.release.outputs.publish_branch }}
- name: Build source distribution
run: python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
docs:
name: Deploy documentation
needs:
- release
- publish-to-pypi
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
ref: ${{ needs.release.outputs.publish_branch }}
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install -r requirements.txt -r requirements-dev.txt -r requirements-client.txt -r requirements-http-client.txt -r requirements-docs.txt
pip install -e .[all]
- name: Set git config
run: |
git config --global user.name "${{ env.GIT_USER_NAME }}"
git config --global user.email "${{ env.GIT_USER_EMAIL }}"
- name: Deploy versioned documentation
run: |
mike deploy --push --remote origin --branch gh-pages --config-file mkdocs.yml ${GITHUB_REF#refs/tags/v}
- name: Deploy stable/latest documentation
if: ${{ needs.release.outputs.publish_branch }} == ${{ env.DEFAULT_RELEASE_BRANCH }}
run: |
mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml ${GITHUB_REF#refs/tags/v} stable
mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ env.DEFAULT_RELEASE_BRANCH }}
publish_container_image:
name: Publish container image
needs:
- release
- publish-to-pypi
uses: ./.github/workflows/cd_container_image.yml
with:
release: true
checkout_ref: ${{ needs.release.outputs.publish_branch }}
secrets: inherit
permissions:
packages: write
contents: read