Skip to content

chore: List required dependencies (#1057) #26

chore: List required dependencies (#1057)

chore: List required dependencies (#1057) #26

Workflow file for this run

name: Publish Python Package
on:
push:
branches:
- main
paths:
- xml2rc/**
- requirements.txt
- setup.cfg
- setup.py
- test.py
tags:
- 'v*'
workflow_dispatch:
inputs:
publish:
description: 'Create Production Release'
required: true
type: boolean
jobs:
publish:
runs-on: ubuntu-latest
outputs:
pkg_version: ${{ steps.semver.outputs.next }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Next Version
if: ${{ github.event.inputs.publish }}
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
branch: main
- name: Set Next Version Env Var
if: ${{ github.event.inputs.publish }}
env:
NEXT_VERSION: ${{ steps.semver.outputs.next }}
run: |
echo "NEXT_VERSION=$next" >> $GITHUB_ENV
- name: Create Draft Release
uses: ncipollo/release-action@v1
if: ${{ github.event.inputs.publish }}
with:
prerelease: true
draft: false
commit: ${{ github.sha }}
tag: ${{ env.NEXT_VERSION }}
name: ${{ env.NEXT_VERSION }}
body: '*pending*'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set Build Variables
run: |
if [[ $NEXT_VERSION ]]; then
echo "Using AUTO SEMVER mode: $NEXT_VERSION"
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
echo "PKG_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=${NEXT_VERSION#?}" >> $GITHUB_ENV
elif [[ "$GITHUB_REF" =~ ^refs/tags/v* ]]; then
echo "Using TAG mode: $GITHUB_REF_NAME"
echo "SHOULD_DEPLOY=true" >> $GITHUB_ENV
echo "PKG_VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=${GITHUB_REF_NAME#?}" >> $GITHUB_ENV
else
echo "Using TEST mode: v3.0.0-dev.$GITHUB_RUN_NUMBER"
echo "SHOULD_DEPLOY=false" >> $GITHUB_ENV
echo "PKG_VERSION=v3.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
echo "PKG_VERSION_STRICT=3.0.0-dev.$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
fi
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install Python dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip setuptools wheel twine build
sudo apt update
sudo apt install -y twine
- name: Build Python package
run: |
source venv/bin/activate
echo "Using version $PKG_VERSION_STRICT"
sed -i -r -e "s/^__version__ += '.*'$/__version__ = '$PKG_VERSION_STRICT'/" xml2rfc/__init__.py
python -m build --config-setting=--build-option="setopt --command=metadata --option=version --set-value=$PKG_VERSION_STRICT"
rm -rf dist
python -m build --sdist
- name: Publish to Test PyPI
if: env.SHOULD_DEPLOY != 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
run: |
echo "Using repository $TWINE_REPOSITORY_URL"
twine check dist/*
twine upload --verbose dist/*
- name: Update CHANGELOG
id: changelog
uses: Requarks/changelog-action@v1
if: env.SHOULD_DEPLOY == 'true'
with:
token: ${{ github.token }}
tag: ${{ env.PKG_VERSION }}
excludeTypes: ''
- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v4
if: env.SHOULD_DEPLOY == 'true'
with:
branch: main
commit_message: 'docs: update CHANGELOG.md + py file versions for ${{ env.PKG_VERSION }} [skip ci]'
file_pattern: CHANGELOG.md setup.cfg xml2rfc/__init__.py
- name: Create Release
uses: ncipollo/release-action@v1
if: env.SHOULD_DEPLOY == 'true'
with:
allowUpdates: true
draft: false
tag: ${{ env.PKG_VERSION }}
name: ${{ env.PKG_VERSION }}
body: ${{ steps.changelog.outputs.changes }}
artifacts: "dist/**"
token: ${{ secrets.GITHUB_TOKEN }}
makeLatest: true
- name: Upload Build Artifacts
uses: actions/[email protected]
with:
name: artifacts
path: |
CHANGELOG.md
setup.cfg
xml2rfc/__init__.py
build-base:
runs-on: ubuntu-latest
if: github.event.inputs.publish
needs: [publish]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Build & Push
uses: docker/build-push-action@v3
with:
context: .
file: docker/base.Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/ietf-tools/xml2rfc-base:latest
build-docs:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
if: github.event.inputs.publish
needs: [build-base]
container: ghcr.io/ietf-tools/xml2rfc-base:latest
env:
PKG_VERSION: ${{needs.publish.outputs.pkg_version}}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v1
- name: Generate docs
run: |
mkdir docs-dist
xml2rfc --docfile --out docs.xml
xml2rfc --html docs.xml --out docs-dist/index.html
cp ./docs-dist/index.html ./docs.html
- name: Add to existing release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
tag: ${{ env.PKG_VERSION }}
artifacts: "docs.html"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate artifact
run: |
tar \
--dereference --hard-dereference \
--directory docs-dist \
-cvf artifact.tar \
--exclude=.git \
--exclude=.github \
.
- name: Upload artifact
uses: actions/upload-artifact@main
with:
name: github-pages
path: artifact.tar
retention-days: 1
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@main