Skip to content

Commit

Permalink
Feature / Automate publishing to PyPI and NPM (#127)
Browse files Browse the repository at this point in the history
* Add a packaging job in CI to publish to PyPI

* Start writing NPM publish task

* Use a script to infer the NPM release tag from the version number

* Minor fix for version_tag.sh

* Minor fix for version_tag.sh

* Fix for packaging.yml workflow

* Make NPM publish step use NPM token

* Test publishing a dev package to NPM

* Set registry in .npmrc for publishing

* Test publishing a dev build to PYPI

* Turn on event guard for PyPI publish action

* Use the latest stable Node/Python versions in packaging workflow

* Extract the NPM tarball before publishing

* Turn on the release guard for NPM publishing, ready to test

* Reset the branch trigger for packaging builds, testing complete
  • Loading branch information
martin-traverse committed Mar 18, 2022
1 parent 01f2142 commit d352f94
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 3 deletions.
87 changes: 84 additions & 3 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ on:


env:
PYTHON_VERSION: "3.9"
NODE_VERSION: "14.x"
PYTHON_VERSION: "3.10"
NODE_VERSION: "16.x"


jobs:
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
with:
fetch-depth: 0

- name: Get TRAC d.a.p. version
- name: Get TRAC version
id: tracdap-version
run: |
tracdap_version=`dev/version.sh`
Expand Down Expand Up @@ -161,3 +161,84 @@ jobs:
asset_path: tracdap-dist-packages-${{ steps.tracdap-version.outputs.tracdap_version }}.tgz
asset_name: tracdap-dist-packages-${{ steps.tracdap-version.outputs.tracdap_version }}.tgz
asset_content_type: application/gzip

publish_to_pypi:

if: ${{ github.event_name == 'release' && github.event.action == 'published' }}

runs-on: ubuntu-latest

needs:
- python_runtime_package

steps:

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Twine
run: |
python -m pip install --upgrade pip
pip install twine
- name: Fetch Python runtime package
uses: actions/download-artifact@v2
with:
name: python_runtime_package
path: tracdap_dist/

- name: Publish to PyPI
env:
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
ls tracdap_dist/*
twine upload --username __token__ tracdap_dist/*
publish_to_npm:

if: ${{ github.event_name == 'release' && github.event.action == 'published' }}

runs-on: ubuntu-latest

needs:
- web_api_package

steps:

# fetch-depth = 0 is needed to get tags for version info
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get TRAC version
id: tracdap-version
run: |
tracdap_version=`dev/version.sh`
echo "tracdap_version = ${tracdap_version}"
echo "::set-output name=tracdap_version::${tracdap_version}"
tracdap_tag=`dev/version_tag.sh ${tracdap_version}`
echo "tracdap_tag = ${tracdap_tag}"
echo "::set-output name=tracdap_tag::${tracdap_tag}"
- name: Fetch web API package
uses: actions/download-artifact@v2
with:
name: web_api_package
path: tracdap_dist/

# NPM publish wants a folder in NPM layout
# So, extract the tarball and publish using the NPM package files
# Also, add an entry in .npmrc to tell NPM to use an auth token from the environment
- name: Publish to NPM
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TAG: ${{ steps.tracdap-version.outputs.tracdap_tag }}
run: |
tar -xzvf tracdap_dist/*
cd package
echo //registry.npmjs.org/:_authToken=\$\{NPM_TOKEN\} >> .npmrc
npm publish --access public --tag ${NPM_TAG}
39 changes: 39 additions & 0 deletions dev/version_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env sh

# Copyright 2022 Accenture Global Solutions Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# For NPM Publish, we need to specify a release tag
# This ia a quick way to generate the tag based on the full version string
# The version number should be as output from version.sh

VERSION=$1

if echo $VERSION | grep -qv "^[0-9]\+\.[0-9]\+\.[0-9]\+"; then
echo "invalid"
exit -1
elif echo $VERSION | grep -q "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; then
echo "latest"
elif echo $VERSION | grep -q "dev"; then
echo "dev"
elif echo $VERSION | grep -q "alpha"; then
echo "alpha"
elif echo $VERSION | grep -q "beta"; then
echo "beta"
elif echo $VERSION | grep -q "rc"; then
echo "rc"
else
echo "invalid"
exit -1
fi

0 comments on commit d352f94

Please sign in to comment.