Skip to content

test changelog json usage for conditional workflow 1/n #37

test changelog json usage for conditional workflow 1/n

test changelog json usage for conditional workflow 1/n #37

Workflow file for this run

---
# this file is *not* meant to cover or endorse the use of GitHub Actions, but
# rather to help make automated releases for this project
name: Upload Python Package to test.pypi.org
on: [pull_request]
permissions:
contents: write
jobs:
test-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# all history is needed to crawl it properly
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install deploy dependencies
run: |
python -m pip install -U poetry twine
poetry self add "poetry-dynamic-versioning[plugin]"
poetry install
- name: Update changelog with snippets
run: |
poetry run changelog-generator \
changelog changelog.md \
--snippets=.snippets \
--in-place
- name: Parse changelog
id: parse_changelog
run: |
poetry run changelog2version --changelog_file changelog.md --print | python -c "import sys, json; print(json.load(sys.stdin)['info']['description'])" > latest_description.txt
echo 'LATEST_DESCRIPTION<<"EOT"' >> $GITHUB_OUTPUT
cat latest_description.txt >> $GITHUB_OUTPUT
echo '"EOT"' >> $GITHUB_OUTPUT
latest_version=$(poetry run changelog2version --changelog_file changelog.md --print | python -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
echo "latest_version=$latest_version" >> $GITHUB_ENV
- name: Parse changelog JSON
id: parse_changelog_json
run: |
poetry run changelog2version \
--changelog_file changelog.md \
--output changelog.json \
--pretty \
--debug
echo "CHANGELOG_JSON=$(jq -c . < changelog.json)" >> $GITHUB_ENV
- name: Check JSON content
# if: ${{ fromJson(env.CHANGELOG_JSON).info.meta.type == 'bugfix' }}
run: |
echo "CHANGELOG_JSON: $CHANGELOG_JSON"
echo "info meta type fromJson: START${{ fromJson(env.CHANGELOG_JSON).info.meta.type }}END"
echo "$CHANGELOG_JSON" | jq ".info.meta.type"
# works, prints "bugfix"
- name: Parse changelog JSON 2
id: parse_changelog_json_2
run: |
value=$(poetry run changelog2version --changelog_file changelog.md --print)
echo "CHANGELOG_JSON_STDOUT=$value" >> $GITHUB_OUTPUT
- name: Check JSON content 2
run: |
echo "Read output: ${{ steps.parse_changelog_json_2.outputs.CHANGELOG_JSON_STDOUT }}"
echo "meta type fromJson: START${{ fromJSON(steps.parse_changelog_json_2.outputs.CHANGELOG_JSON_STDOUT).info.meta.type }}END"
- name: Build package
run: |
poetry run changelog2version \
--changelog_file changelog.md \
--version_file snippets2changelog/version.py \
--version_file_type py \
--additional_version_info="-rc${{ github.run_number }}.dev${{ github.event.number }}" \
--debug
poetry build
- name: Test built package
run: |
twine check dist/*.tar.gz
# - name: Archive build package artifact
# uses: actions/upload-artifact@v4
# with:
# # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
# # ${{ github.repository }} and ${{ github.ref_name }} can't be used for artifact name due to unallowed '/'
# name: dist_py.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ github.run_number }}
# path: dist/*.tar.gz
# retention-days: 14
# - name: Publish package
# uses: pypa/gh-action-pypi-publish@release/v1.5
# with:
# repository_url: https://test.pypi.org/legacy/
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# skip_existing: true
# verbose: true
# print_hash: true
# - name: Create Prerelease
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ env.latest_version }}-rc${{ github.run_number }}.dev${{ github.event.number }}
# release_name: ${{ env.latest_version }}-rc${{ github.run_number }}.dev${{ github.event.number }}
# body: ${{ steps.parse_changelog.outputs.LATEST_DESCRIPTION }}
# draft: false
# prerelease: true