Fix PyPI package on Python>=3.9. #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: [push, pull_request] | |
name: Test & publish | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
- name: Prepare metadata | |
run: node prepare.mjs | |
- name: Install dependencies | |
run: npm install | |
- name: Build generated code | |
run: npm run build | |
- name: Run tests | |
run: npm run test | |
- name: Build JavaScript artifact | |
run: | | |
mkdir -p dist | |
npm pack --pack-destination dist | |
- name: Upload JavaScript artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist-npmjs | |
path: dist/ | |
- name: Build Python artifact | |
run: | | |
pip install build | |
python -m build pypi | |
- name: Upload Python artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist-pypi | |
path: pypi/dist/ | |
check: # group all `test (*)` workflows into one for the required status check | |
needs: test | |
if: ${{ always() && !contains(needs.*.result, 'cancelled') }} | |
runs-on: ubuntu-latest | |
steps: | |
- run: ${{ contains(needs.*.result, 'failure') && 'false' || 'true' }} | |
publish-python: | |
needs: check | |
if: ${{ github.event_name == 'push' && github.repository == 'YoWASP/wavedrom' && github.event.ref == 'refs/heads/main' }} | |
runs-on: ubuntu-latest | |
environment: publish | |
permissions: | |
id-token: write | |
steps: | |
- name: Download Python artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-pypi | |
path: dist-tree/ | |
- name: Prepare artifacts for publishing | |
run: | | |
mkdir dist | |
find dist-tree -name '*.whl' -exec mv {} dist/ \; | |
- name: Publish wheels to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
publish-javascript: | |
needs: check | |
if: ${{ github.event_name == 'push' && github.repository == 'YoWASP/wavedrom' && github.event.ref == 'refs/heads/main' }} | |
runs-on: ubuntu-latest | |
environment: publish | |
permissions: | |
id-token: write | |
steps: | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
registry-url: 'https://registry.npmjs.org' | |
- name: Download JavaScript artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-npmjs | |
path: dist/ | |
- name: Publish package to NPM | |
run: npm publish --access public $(find dist -name *.tgz -printf 'file:%p ') | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NPM_CONFIG_PROVENANCE: true |