Skip to content

Commit 28221ff

Browse files
👷 [#120] Automate publishing of Python and NPM packages
* Publish to NPM automatically * Use trusted publishing for PyPI packages
1 parent a7539d1 commit 28221ff

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