66 - published
77
88env :
9- PUBLISH_UPDATE_BRANCH : master
109 GIT_USER_NAME : OPTIMADE Developers
1110 GIT_USER_EMAIL :
" [email protected] " 11+ DEFAULT_RELEASE_BRANCH : " master"
1212
1313jobs :
14-
15- publish :
16- name : Publish OPTIMADE Python tools
14+ release :
15+ name : Release OPTIMADE Python tools
1716 runs-on : ubuntu-latest
1817 if : github.repository == 'Materials-Consortia/optimade-python-tools' && startsWith(github.ref, 'refs/tags/v')
18+ outputs :
19+ publish_branch : ${{ steps.save_branch.outputs.publish_branch }}
1920
2021 steps :
21- - name : Checkout repository
22- uses : actions/checkout@v3
22+ - name : Get triggering branch
23+ 24+ id : get_release_branch
25+ with :
26+ route : GET /repos/{owner}/{repo}/releases/tags/${{ github.ref_name }}
27+ # Note, the following inputs might give warnings that they are not valid.
28+ # This is due to the flexible nature of the `octokit/request-action`.
29+ # Fore more information see: https://github.com/octokit/request-action/tree/v2.x?tab=readme-ov-file#warnings
30+ owner : Materials-Consortia
31+ repo : optimade-python-tools
32+ env :
33+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
34+
35+ - name : Save branch name
36+ id : save_branch
37+ run : |
38+ echo 'publish_branch=${{ fromJson(steps.get_release_branch.outputs.data).target_commitish }}' >> $GITHUB_OUTPUT
39+
40+ - name : Checkout publish branch
41+ uses : actions/checkout@v4
2342 with :
2443 submodules : true
2544 fetch-depth : 0
45+ ref : ${{ steps.save_branch.outputs.publish_branch }}
2646
2747 - name : Set up Python 3.10
28- uses : actions/setup-python@v4
48+ uses : actions/setup-python@v5
2949 with :
3050 python-version : ' 3.10'
3151
@@ -36,70 +56,98 @@ jobs:
3656 pip install -r requirements.txt -r requirements-dev.txt -r requirements-client.txt -r requirements-http-client.txt -r requirements-docs.txt
3757 pip install -e .[all]
3858
59+ - name : Setup changelog configuration
60+ id : changelog_config
61+ run : |
62+ echo "project=$(echo $GITHUB_REPOSITORY | cut -d/ -f2- )" >> $GITHUB_OUTPUT
63+ echo "exclude_labels=duplicate,question,invalid,wontfix,dependency_updates,skip_changelog" >> $GITHUB_OUTPUT
64+
65+ # For the release-specific changelog
66+ echo "output_file=release_changelog.md" >> $GITHUB_OUTPUT
67+
3968 - name : Update changelog
40- uses : CharMixer/auto -changelog-action@v1
69+ uses : docker://githubchangeloggenerator/github -changelog-generator:1.16.2
4170 with :
42- token : ${{ secrets.RELEASE_PAT_BOT }}
43- release_branch : ${{ env.PUBLISH_UPDATE_BRANCH }}
44- exclude_labels : " duplicate,question,invalid,wontfix,dependency_updates,skip_changelog"
71+ 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 }}"
4572
4673 - name : Update API Reference docs and version - Commit changes and update tag
4774 run : .github/utils/update_docs.sh
4875
49- - name : Update '${{ env.PUBLISH_UPDATE_BRANCH }}'
76+ - name : Update triggering branch
5077 uses : CasperWA/push-protected@v2
5178 with :
5279 token : ${{ secrets.RELEASE_PAT_BOT }}
53- branch : ${{ env.PUBLISH_UPDATE_BRANCH }}
80+ branch : ${{ steps.save_branch.outputs.publish_branch }}
5481 unprotect_reviews : true
5582 sleep : 15
5683 force : true
5784 tags : true
5885
59- - name : Get tagged versions
60- run : echo "PREVIOUS_VERSION=$(git tag -l --sort -version:refname | sed -n 2p)" >> $GITHUB_ENV
86+ - name : Get previous version
87+ id : get_previous_version
88+ run : echo "previous_version=$(git tag -l --sort -version:refname | sed -n 2p)" >> $GITHUB_OUTPUT
6189
6290 - name : Create release-specific changelog
63- uses : CharMixer/auto -changelog-action@v1
91+ uses : docker://githubchangeloggenerator/github -changelog-generator:1.16.2
6492 with :
65- token : ${{ secrets.RELEASE_PAT_BOT }}
66- release_branch : ${{ env.PUBLISH_UPDATE_BRANCH }}
67- since_tag : " ${{ env.PREVIOUS_VERSION }}"
68- output : " release_changelog.md"
69- exclude_labels : " duplicate,question,invalid,wontfix,dependency_updates,skip_changelog"
93+ 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 }}"
7094
7195 - name : Append changelog to release body
7296 run : |
7397 gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} --jq '.body' > release_body.md
74- cat release_changelog.md >> release_body.md
98+ cat ${{ steps.changelog_config.outputs.output_file }} >> release_body.md
7599 gh api /repos/${{ github.repository }}/releases/${{ github.event.release.id }} -X PATCH -F body='@release_body.md'
76100 env :
77101 GITHUB_TOKEN : ${{ secrets.RELEASE_PAT_BOT }}
78102
103+ publish-to-pypi :
104+ name : Publish to PyPI
105+ needs : release
106+ runs-on : ubuntu-latest
107+
108+ environment :
109+ name : pypi
110+ url : https://pypi.org/p/optimade
111+
112+ permissions :
113+ id-token : write # Important for Trusted Publishing on PyPI
114+
115+ steps :
116+ - name : Install prerequisites
117+ run : python -m pip install build
118+
119+ - name : Checkout repository
120+ uses : actions/checkout@v4
121+ with :
122+ submodules : true
123+ fetch-depth : 0
124+ ref : ${{ needs.release.outputs.publish_branch }}
125+
79126 - name : Build source distribution
80127 run : python -m build
81128
82129 - name : Publish package to PyPI
83130 uses : pypa/gh-action-pypi-publish@release/v1
84131 with :
85- user : __token__
86- password : ${{ secrets.PYPI_PASSWORD }}
132+ print-hash : true
87133
88134 docs :
89135 name : Deploy documentation
90- needs : publish
136+ needs :
137+ - release
138+ - publish-to-pypi
91139 runs-on : ubuntu-latest
92140
93141 steps :
94142 - name : Checkout repository
95- uses : actions/checkout@v3
143+ uses : actions/checkout@v4
96144 with :
97145 submodules : true
98146 fetch-depth : 0
99- ref : ${{ env.PUBLISH_UPDATE_BRANCH }}
147+ ref : ${{ needs.release.outputs.publish_branch }}
100148
101149 - name : Set up Python 3.10
102- uses : actions/setup-python@v4
150+ uses : actions/setup-python@v5
103151 with :
104152 python-version : ' 3.10'
105153
@@ -115,18 +163,25 @@ jobs:
115163 git config --global user.name "${{ env.GIT_USER_NAME }}"
116164 git config --global user.email "${{ env.GIT_USER_EMAIL }}"
117165
118- - name : Deploy documentation
166+ - name : Deploy versioned documentation
167+ run : |
168+ mike deploy --push --remote origin --branch gh-pages --config-file mkdocs.yml ${GITHUB_REF#refs/tags/v}
169+
170+ - name : Deploy stable/latest documentation
171+ if : ${{ needs.release.outputs.publish_branch }} == ${{ env.DEFAULT_RELEASE_BRANCH }}
119172 run : |
120173 mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml ${GITHUB_REF#refs/tags/v} stable
121- mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest master
174+ mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ env.DEFAULT_RELEASE_BRANCH }}
122175
123176 publish_container_image :
124177 name : Publish container image
125- needs : publish
178+ needs :
179+ - release
180+ - publish-to-pypi
126181 uses : ./.github/workflows/cd_container_image.yml
127182 with :
128183 release : true
129- checkout_ref : master
184+ checkout_ref : ${{ needs.release.outputs.publish_branch }}
130185 secrets : inherit
131186 permissions :
132187 packages : write
0 commit comments