Skip to content

Commit 5a4d08e

Browse files
👷 [#120] Automate publishing of Python and NPM packages
* Publish to NPM automatically * Use trusted publishing for PyPI packages
1 parent 07d454b commit 5a4d08e

File tree

2 files changed

+52
-56
lines changed

2 files changed

+52
-56
lines changed

.github/workflows/ci.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,55 @@ jobs:
8181
uses: codecov/codecov-action@v3
8282
with:
8383
directory: reports/
84+
85+
86+
publish:
87+
name: Publish package to PyPI
88+
runs-on: ubuntu-latest
89+
needs:
90+
- tests
91+
- e2e_tests
92+
93+
if: github.repository == 'django-commons/django-cookie-consent' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
94+
95+
environment:
96+
name: release
97+
url: https://pypi.org/project/django-cookie-consent/
98+
permissions:
99+
id-token: write
100+
101+
steps:
102+
- uses: actions/checkout@v4
103+
- uses: actions/setup-python@v5
104+
with:
105+
python-version: '3.12'
106+
- uses: actions/setup-node@v4
107+
with:
108+
node-version-file: 'js/.nvmrc'
109+
cache: npm
110+
registry-url: 'https://registry.npmjs.org'
111+
112+
# Required to ensure the build artifacts are in the packages.
113+
- uses: ./.github/actions/build-js
114+
with:
115+
npm-package: 'true'
116+
django-staticfiles: 'true'
117+
118+
- name: Build sdist and wheel
119+
run: |
120+
pip install build --upgrade
121+
python -m build
122+
123+
# TODO: enable verified publishing!
124+
- name: Publish a Python distribution to PyPI
125+
uses: pypa/gh-action-pypi-publish@release/v1
126+
127+
- name: Publish NPM package to Github
128+
run: |
129+
# Strip git ref prefix from version
130+
version=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
131+
132+
npm publish --new-version="$version" --provenance
133+
working-directory: js
134+
env:
135+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)