Skip to content

Commit 7dbb254

Browse files
Add create release & publish to pypi actions (#4)
2 parents b13be9e + 1e3fa19 commit 7dbb254

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: frequenz-api-dispatch
22

3-
on: [pull_request, push, release]
3+
on: [pull_request, push]
44

55
# Ensure old CI runs still being in progress are cancelled.
66
concurrency:
@@ -58,3 +58,97 @@ jobs:
5858
python -m pip install .[dev-noxfile]
5959
- name: Run nox
6060
run: nox
61+
62+
build-dist:
63+
runs-on: ubuntu-20.04
64+
steps:
65+
- name: Fetch sources
66+
uses: actions/checkout@v3
67+
with:
68+
submodules: true
69+
70+
- name: Set up Python
71+
uses: actions/setup-python@v4
72+
with:
73+
python-version: "3.11"
74+
75+
- name: Install build dependencies
76+
run: |
77+
python -m pip install -U pip
78+
python -m pip install -U build
79+
80+
- name: Build the source and binary distribution
81+
run: python -m build
82+
83+
- name: Upload dist files
84+
uses: actions/upload-artifact@v3
85+
with:
86+
name: frequenz-api-dispatch-dist
87+
path: dist/
88+
if-no-files-found: error
89+
90+
create-github-release:
91+
needs: ["protolint", "gen-docs", "tests", "build-dist"]
92+
# Create a release only on tags creation
93+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
94+
permissions:
95+
# We need write permissions on contents to create GitHub releases and on
96+
# discussions to create the release announcement in the discussion forums
97+
contents: write
98+
discussions: write
99+
runs-on: ubuntu-20.04
100+
steps:
101+
- name: Download dist files
102+
uses: actions/download-artifact@v3
103+
with:
104+
name: frequenz-api-dispatch-dist
105+
path: dist
106+
107+
- name: Download RELEASE_NOTES.md
108+
run: |
109+
set -ux
110+
gh api \
111+
-X GET \
112+
-f ref=$REF \
113+
-H "Accept: application/vnd.github.raw" \
114+
"/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \
115+
> RELEASE_NOTES.md
116+
env:
117+
REF: ${{ github.ref }}
118+
REPOSITORY: ${{ github.repository }}
119+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120+
121+
- name: Create GitHub release
122+
run: |
123+
set -ux
124+
extra_opts=
125+
if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi
126+
gh release create \
127+
-R "$REPOSITORY" \
128+
--discussion-category announcements \
129+
--notes-file RELEASE_NOTES.md \
130+
--generate-notes \
131+
$extra_opts \
132+
$REF_NAME \
133+
dist/*
134+
env:
135+
REF_NAME: ${{ github.ref_name }}
136+
REPOSITORY: ${{ github.repository }}
137+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138+
139+
publish-to-pypi:
140+
needs: ["create-github-release"]
141+
runs-on: ubuntu-20.04
142+
permissions:
143+
# For trusted publishing. See:
144+
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
145+
id-token: write
146+
steps:
147+
- name: Download dist files
148+
uses: actions/download-artifact@v3
149+
with:
150+
name: frequenz-api-dispatch-dist
151+
path: dist
152+
153+
- name: Publish the Python distribution to PyPI
154+
uses: pypa/gh-action-pypi-publish@release/v1

0 commit comments

Comments
 (0)