Test & Release #63
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: Test & Release | |
on: workflow_dispatch | |
jobs: | |
pre-commit: | |
name: run pre-commit hook | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- uses: pre-commit/[email protected] | |
test: | |
name: run tox tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install krb5-config libvirt-dev # missing distro dependencies | |
run: sudo apt update && sudo apt-get install libkrb5-dev libvirt-dev | |
- uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Install Tox and any other packages | |
run: pip install tox | |
- name: Run Tox | |
run: tox -e py | |
release: | |
name: mrack semantic release 🐕 | |
runs-on: ubuntu-latest | |
needs: [pre-commit, test] | |
if: github.repository == 'neoave/mrack' | |
outputs: | |
new_version: ${{ steps.set_version.outputs.new_version }} | |
steps: | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Display Python version | |
run: python --version | |
- name: Set up changelog date to use later | |
run: echo "TODAY=`date "+%a %b %d %Y"`" >> ${GITHUB_ENV} | |
- name: Set RELEASE_ACTOR | |
env: | |
RELEASE_ACTOR_TIBORIS: ${{ secrets.RELEASE_ACTOR_TIBORIS }} | |
RELEASE_ACTOR_DAV_PASCUAL: ${{ secrets.RELEASE_ACTOR_DAV_PASCUAL }} | |
RELEASE_ACTOR_PVOBORNI: ${{ secrets.RELEASE_ACTOR_PVOBORNI }} | |
RELEASE_ACTOR_KALEEMSIDDIQU: ${{ secrets.RELEASE_ACTOR_KALEEMSIDDIQU }} | |
run: | | |
RELEASE_ACTOR=RELEASE_ACTOR_$(echo ${GITHUB_ACTOR^^} | tr - _) | |
echo "RELEASE_ACTOR=${!RELEASE_ACTOR}" >> ${GITHUB_ENV} | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false # do not set the actions user to git config | |
fetch-depth: 0 | |
- name: Get the new version using python-semantic-release | |
run: | | |
pip3 install python-semantic-release==8.1.1 | |
echo "NEW_VERSION="`semantic-release version --print` >> ${GITHUB_ENV} | |
- name: Update the mrack.spec changelog with initiator and basic message | |
run: | | |
# get the history of commits and generate changelog from it | |
git log --pretty=format:"- %h %s (%cn)" $(git describe --tags --abbrev=0)..HEAD > changelog_changes | |
# add newline after generated changelog for changelog sections to be visually separated | |
echo -e "\n" >> changelog_changes | |
echo "============NEW CHANGELOG=================" | |
cat changelog_changes | |
echo "==========================================" | |
# write changelog to mrack.spec | |
sed -i '/%changelog/r changelog_changes' mrack.spec | |
# write header of changelog to mrack.spec | |
sed -ri \ | |
"s/\%changelog/\%changelog\\n\*\ $TODAY\ $RELEASE_ACTOR\ -\ $NEW_VERSION-1/" \ | |
mrack.spec | |
- name: Add version to specfile | |
run: | | |
export SPEC_VERSION_REGEX="s/^Version:(\s+)(.*)/Version:\1$NEW_VERSION/" | |
echo $SPEC_VERSION_REGEX | |
sed -i -E $SPEC_VERSION_REGEX mrack.spec | |
- name: Add specfile to commit | |
run: git add mrack.spec | |
- name: Python Semantic Release | |
uses: python-semantic-release/[email protected] | |
with: | |
github_token: ${{ secrets.TIBORIS_GH_TOKEN }} | |
- name: Set NEW_VERSION as output | |
id: set_version | |
run: echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
copr-build: | |
name: Copr 📦 build for mrack | |
runs-on: ubuntu-latest | |
needs: [release] | |
steps: | |
- name: Trigger COPR build | |
run: curl -X POST ${{ secrets.COPR_WEBHOOK_URL }} | |
python-build: | |
name: Build 🐍 distribution 📦 | |
runs-on: ubuntu-latest | |
needs: [release] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Checkout latest release commit | |
run: | | |
git fetch | |
git checkout $(git rev-parse FETCH_HEAD) | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Install pypa/build | |
run: >- | |
python3 -m | |
pip install | |
build | |
--user | |
- name: Build a binary wheel and a source tarball | |
run: python3 -m build | |
- name: Store the distribution packages | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Upload Release Asset | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh release upload v${{ needs.release.outputs.new_version }} dist/* | |
publish-to-pypi: | |
name: >- | |
Publish 🐍 distribution 📦 to PyPI | |
needs: [python-build] | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/project/mrack/ | |
# IMPORTANT: mandatory for trusted publishing which is setup on pypi | |
permissions: | |
id-token: write | |
steps: | |
- name: Download all the dists from artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: list dist dir | |
run: ls -la dist/ | |
- name: Publish distribution 📦 to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 |