Workflow file for this run
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
name: Upload Python Package to PyPI and nodejs bindings to npm | |
on: | |
release: | |
types: [ published ] | |
jobs: | |
update-version: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: main | |
fetch-depth: 0 | |
token: ${{ secrets.PUSH_GITHUB_TOKEN }} | |
- name: Update Version to Release Tag | |
run: | | |
# Extract the release tag number | |
TAG=$(echo "${{ github.event.release.tag_name }}" | sed -E 's/v([0-9]+\.[0-9]+\.[0-9]+)/\1/') | |
# Update the version file (version.py) | |
sed -i "s/__version__ = \".*\"/__version__ = \"$TAG\"/" src/hvps/version.py | |
# Update the package.json file for bindings | |
sed -i "s/\"version\": \".*\"/\"version\": \"$TAG\"/" bindings/nodejs/hvps/package.json | |
# Update the package.json file for nodered | |
sed -i "s/\"version\": \".*\"/\"version\": \"$TAG\"/" bindings/nodejs/nodered/package.json | |
sed -i "s/\"hvps\": \".*\"/\"hvps\": \"$TAG\"/" bindings/nodejs/nodered/package.json | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
- name: Run pre-commit | |
run: | | |
python -m pip install pre-commit | |
pre-commit run --all-files || true # ignore errors, we want to format the files | |
- name: Commit and push changes | |
run: | | |
git config --local user.name "Luis Antonio Obis Aparicio" | |
git config --local user.email "[email protected]" | |
git add src/hvps/version.py bindings/nodejs/hvps/*.json bindings/nodejs/nodered/*.json | |
git commit -m "Update version to ${{ github.event.release.tag_name }}" | |
git push origin HEAD:main | |
- name: cache source code after modification | |
uses: actions/cache@v3 | |
with: | |
path: ${{ github.workspace }} | |
key: ${{ runner.os }}-src-${{ github.sha }}-${{ github.run_id}}-${{ github.run_number }} | |
build: | |
runs-on: ubuntu-latest | |
needs: [ update-version ] | |
defaults: | |
run: | |
working-directory: ${{ github.workspace }} | |
steps: | |
- name: restore source code from cache (contains update to version) | |
uses: actions/cache@v3 | |
with: | |
path: ${{ github.workspace }} | |
key: ${{ runner.os }}-src-${{ github.sha }}-${{ github.run_id}}-${{ github.run_number }} | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
- name: Build package 📦 | |
run: python -m build | |
- name: Install package 📦 | |
run: python -m pip install . | |
- name: Verify python package version matches tag | |
run: | | |
python -c "import hvps; assert '${{ github.event.release.tag_name }}' == 'v' + hvps.__version__" | |
- name: Verify npm package version matches tag | |
run: | | |
python -c "import os,json;version=json.load(open('bindings/nodejs/hvps/package.json'))['version'];assert '${{ github.event.release.tag_name }}' == 'v' + version" | |
- name: Cache dist directory | |
uses: actions/cache@v3 | |
with: | |
path: dist | |
key: ${{ runner.os }}-dist-${{ github.sha }}-${{ github.run_id}}-${{ github.run_number }} | |
publish-to-pypi: | |
needs: [ build ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Restore dist from cache | |
uses: actions/cache@v3 | |
with: | |
path: dist | |
key: ${{ runner.os }}-dist-${{ github.sha }}-${{ github.run_id}}-${{ github.run_number }} | |
- name: Publish package 📦 to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
publish-bindings-to-npm: | |
needs: [ publish-to-pypi ] | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: bindings/nodejs/hvps | |
steps: | |
- name: restore source code from cache (contains update to version) | |
uses: actions/cache@v3 | |
with: | |
path: ${{ github.workspace }} | |
key: ${{ runner.os }}-src-${{ github.sha }}-${{ github.run_id}}-${{ github.run_number }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: 'npm' | |
cache-dependency-path: bindings/nodejs/hvps/package-lock.json | |
registry-url: 'https://registry.npmjs.org' | |
- name: Install dependencies | |
run: npm ci | |
- name: Publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
publish-node-to-npm: | |
needs: [ publish-bindings-to-npm ] | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: bindings/nodejs/nodered | |
steps: | |
- name: restore source code from cache (contains update to version) | |
uses: actions/cache@v3 | |
with: | |
path: ${{ github.workspace }} | |
key: ${{ runner.os }}-src-${{ github.sha }}-${{ github.run_id}}-${{ github.run_number }} | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: 'npm' | |
cache-dependency-path: bindings/nodejs/nodered/package-lock.json | |
registry-url: 'https://registry.npmjs.org' | |
- name: Update package-lock.json | |
run: npm install | |
- name: Push changes | |
run: | | |
git config --local user.name "Luis Antonio Obis Aparicio" | |
git config --local user.email "[email protected]" | |
git add package-lock.json | |
git commit -m "Update nodered package-lock.json" | |
git push origin HEAD:main | |
- name: Install dependencies | |
run: npm ci | |
- name: Publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |