Merge pull request #56 from sicpa-dlab/main #39
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: release | |
on: | |
push: | |
branches: [stable] | |
workflow_dispatch: | |
inputs: | |
devN: | |
description: 'development release number' | |
required: false | |
default: '0' | |
env: | |
PKG_NAME: peerdid | |
jobs: | |
checks: | |
name: check releases | |
if: github.ref == 'refs/heads/stable' | |
runs-on: ubuntu-latest | |
outputs: | |
current_version: ${{ steps.current_version.outputs.current_version }} | |
release_info: ${{ steps.release_info.outputs.release_info }} | |
asset_tgz_url: ${{ steps.release_info.outputs.asset_tgz_url }} | |
asset_whl_url: ${{ steps.release_info.outputs.asset_whl_url }} | |
upload_url: ${{ steps.release_info.outputs.upload_url }} | |
already_in_pypi: ${{ steps.check_in_pypi.outputs.pypi_versions != '' }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Get current version | |
id: current_version | |
run: | | |
python -m pip install . --no-deps | |
out="$(pip show ${{ env.PKG_NAME }} | grep 'Version:' | awk '{print $2}')" | |
echo "$out" | |
echo "current_version=$out" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Get release info | |
id: release_info | |
run: | | |
release_info="$(curl -s https://api.github.com/repos/${{ github.repository }}/releases \ | |
| jq -c '.[] | select(.name == "v${{ steps.current_version.outputs.current_version }}")')" | |
echo "release_info=$release_info" >> $GITHUB_OUTPUT | |
echo "$release_info" | |
asset_tgz_url="$(echo "$release_info" \ | |
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.tar.gz$")) | .browser_download_url')" | |
echo "asset_tgz_url=$asset_tgz_url" >> $GITHUB_OUTPUT | |
echo "$asset_tgz_url" | |
asset_whl_url="$(echo "$release_info" \ | |
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.whl$")) | .browser_download_url')" | |
echo "asset_whl_url=$asset_whl_url" >> $GITHUB_OUTPUT | |
echo "$asset_whl_url" | |
upload_url="$(echo "$release_info" | jq -r '.upload_url')" | |
echo "upload_url=$upload_url" >> $GITHUB_OUTPUT | |
echo "$upload_url" | |
shell: bash | |
- name: check if already deployed to PyPI | |
id: check_in_pypi | |
# Note. other options: | |
# - use 'pip install --no-deps PKG==VERSION' with current version | |
# - use 'pip index versions PKG==VERSION' | |
# (but it's a kind of experimental feature of pip >= 21.2) | |
run: | | |
python -m pip install --upgrade pip | |
out="$(pip install --use-deprecated=legacy-resolver ${{ env.PKG_NAME }}== 2>&1 \ | |
| grep -E "Could not find .* ${{ steps.current_version.outputs.current_version }}(,|\))")" | |
echo "pypi_versions=$out" >> $GITHUB_OUTPUT | |
shell: bash {0} # to opt-out of default fail-fast behavior | |
release-github: | |
name: GitHub Release | |
if: github.ref == 'refs/heads/stable' | |
runs-on: ubuntu-latest | |
needs: checks | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: build dist | |
id: build_assets | |
if: ${{ !(needs.checks.outputs.asset_tgz_url && needs.checks.outputs.asset_whl_url) }} | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install --upgrade build | |
python -m build | |
ls dist | |
asset_tgz_name="$(find dist -name '*.tar.gz' -printf '%f')" | |
echo "asset_tgz_name=$asset_tgz_name" >> $GITHUB_OUTPUT | |
asset_whl_name="$(find dist -name '*.whl' -printf '%f')" | |
echo "asset_whl_name=$asset_whl_name" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Create Release | |
id: create_release | |
if: ${{ ! needs.checks.outputs.release_info }} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ needs.checks.outputs.current_version }} | |
release_name: v${{ needs.checks.outputs.current_version }} | |
- name: Set upload url | |
id: upload_url | |
if: ${{ !(needs.checks.outputs.asset_tgz_url && needs.checks.outputs.asset_whl_url) }} | |
run: | | |
if [[ -n "${{ needs.checks.outputs.upload_url }}" ]]; then | |
echo "value=${{ needs.checks.outputs.upload_url }}" >> $GITHUB_OUTPUT | |
else | |
echo "value=${{ steps.create_release.outputs.upload_url }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Upload the source archive | |
if: ${{ !needs.checks.outputs.asset_tgz_url }} | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.upload_url.outputs.value }} | |
asset_path: dist/${{ steps.build_assets.outputs.asset_tgz_name }} | |
asset_name: ${{ steps.build_assets.outputs.asset_tgz_name }} | |
asset_content_type: application/x-gtar | |
- name: Upload the wheel | |
if: ${{ !needs.checks.outputs.asset_whl_url }} | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.upload_url.outputs.value }} | |
asset_path: dist/${{ steps.build_assets.outputs.asset_whl_name }} | |
asset_name: ${{ steps.build_assets.outputs.asset_whl_name }} | |
asset_content_type: application/zip | |
deploy-pypi: | |
name: Deploy to PyPI | |
if: github.ref == 'refs/heads/stable' && needs.checks.outputs.already_in_pypi == 'false' | |
runs-on: ubuntu-latest | |
needs: [checks, release-github] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: download GitHub artifacts | |
run: | | |
mkdir -p dist | |
cd dist | |
curl -s https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ needs.checks.outputs.current_version }} \ | |
| jq -r ".assets[] | select(.name | contains(\"${{ env.PKG_NAME }}\")) | .browser_download_url" \ | |
| wget -i - | |
ls | |
shell: bash | |
# NOTE uncomment once community actions are allowed for the github org | |
# - name: Publish to PyPI | |
# uses: pypa/gh-action-pypi-publish@v1.4.2 | |
# with: | |
# user: __token__ | |
# password: ${{ secrets.PYPI_API_TOKEN }} | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Prepare python env | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install --upgrade twine | |
shell: bash | |
- name: Publish to PyPI | |
env: | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: python -m twine upload --non-interactive --username __token__ dist/* | |
shell: bash | |
deploy-test-pypi: | |
name: Deploy to TestPyPI | |
if: github.ref != 'refs/heads/stable' && github.event_name == 'workflow_dispatch' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: set dev version | |
run: | | |
sed -i -r "s~__version__ = \"(.+)\"~__version__ = \"\1.dev${{ github.event.inputs.devN }}\"~" ./peerdid/__init__.py | |
grep version ./setup.py | |
shell: bash | |
- name: build dist | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install --upgrade build | |
python -m build | |
ls dist | |
shell: bash | |
- name: install twine | |
run: python -m pip install --upgrade twine | |
shell: bash | |
- name: Publish to TestPyPI | |
env: | |
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
run: python -m twine upload --non-interactive --username __token__ --repository testpypi dist/* | |
shell: bash |