Merge pull request #98 from sicpa-dlab/main #35
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: didcomm | |
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@v2 | |
- name: Setup Python | |
id: setup | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: pip install tomli | |
- name: Get current version | |
id: current_version | |
run: python ./.github/scripts/current_version.py | |
- name: Get release info | |
id: release_info | |
run: | | |
release_info="$(curl -s https://api.github.com/repos/${{ github.repository }}/releases \ | |
| jq '.[] | select(.name == "v${{ steps.current_version.outputs.current_version }}")')" | |
echo "::set-output name=release_info::$release_info" | |
echo "$release_info" | |
asset_tgz_url="$(echo "$release_info" \ | |
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.tar.gz$")) | .browser_download_url')" | |
echo "::set-output name=asset_tgz_url::$asset_tgz_url" | |
echo "$asset_tgz_url" | |
asset_whl_url="$(echo "$release_info" \ | |
| jq -r '.assets[] | select(.name | match("^${{ env.PKG_NAME }}.*\\.whl$")) | .browser_download_url')" | |
echo "::set-output name=asset_whl_url::$asset_whl_url" | |
echo "$asset_whl_url" | |
upload_url="$(echo "$release_info" | jq -r '.upload_url')" | |
echo "::set-output name=upload_url::$upload_url" | |
echo "$upload_url" | |
- 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 "::set-output name=pypi_versions::$out" | |
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 | |
- name: Install poetry | |
run: pipx install poetry | |
- uses: actions/setup-python@v4 | |
id: setup | |
with: | |
python-version: '3.x' | |
cache: 'poetry' | |
- name: Install dependencies | |
if: steps.setup.outputs.cache-hit != 'true' | |
run: poetry install | |
- name: build dist | |
id: build_assets | |
if: ${{ !(needs.checks.outputs.asset_tgz_url && needs.checks.outputs.asset_whl_url) }} | |
run: | | |
poetry build | |
asset_tgz_name="$(find dist -name '*.tar.gz' -printf '%f')" | |
echo "::set-output name=asset_tgz_name::$asset_tgz_name" | |
asset_whl_name="$(find dist -name '*.whl' -printf '%f')" | |
echo "::set-output name=asset_whl_name::$asset_whl_name" | |
- 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 "::set-output name=value::${{ needs.checks.outputs.upload_url }}" | |
else | |
echo "::set-output name=value::${{ steps.create_release.outputs.upload_url }}" | |
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: Install poetry | |
run: pipx install poetry | |
- 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 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Publish to PyPI | |
env: | |
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }} | |
run: poetry publish | |
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 | |
- name: Get current version | |
id: current_version | |
run: | | |
pip install tomli | |
python ./.github/scripts/current_version.py | |
- name: Install poetry | |
run: pipx install poetry | |
- uses: actions/setup-python@v4 | |
id: setup | |
with: | |
python-version: '3.x' | |
cache: 'poetry' | |
- name: Install dependencies | |
if: steps.setup.outputs.cache-hit != 'true' | |
run: poetry install | |
- name: set dev version | |
run: | | |
poetry version "${{ steps.current_version.outputs.current_version }}.dev${{ github.event.inputs.devN }}" | |
- name: build dist | |
run: poetry build | |
- name: Publish to Test PyPI | |
env: | |
POETRY_PYPI_TOKEN_TEST_PYPI: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
poetry config repositories.test-pypi https://test.pypi.org/legacy/ | |
poetry publish -r test-pypi |