Skip to content

Commit

Permalink
build: add release functionality (handles versioning, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
autumnjolitz committed Jun 27, 2024
1 parent db40452 commit c1de740
Show file tree
Hide file tree
Showing 5 changed files with 580 additions and 133 deletions.
139 changes: 28 additions & 111 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Tests
name: Mainline tests/verifications

on:
push:
tags: '*'
branches: [ master, main ]
pull_request:
branches: [ master, main ]
Expand All @@ -25,7 +24,7 @@ jobs:
-
name: Install dependencies
run: |
python -m pip install --upgrade pip invoke
python -m pip install --upgrade pip invoke typing-extensions
invoke setup --devel --tests
-
name: Lint with flake8
Expand All @@ -50,64 +49,15 @@ jobs:
-
name: Install dependencies
run: |
python -m pip install --upgrade pip invoke
python -m pip install --upgrade pip invoke typing-extensions
invoke setup --devel --tests
-
name: validate types
run: |
python/bin/python -m mypy instruct
update-changelog:
needs: [verify_style, verify_types]
runs-on: 'ubuntu-latest'
permissions:
contents: write
steps:
-
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: 'x64'
-
name: Setup
run: |
python -m pip install --upgrade pip invoke typing-extensions
invoke setup --devel --no-project
-
name: Warn changelog out of sync
if: ${{ github.ref_type != 'tag' }}
run: |
invoke update-changes
if ! git diff-index --quiet HEAD --
then
echo '::warn file=CHANGES.rst,line=1,title=CHANGES.rst out of sync::Expected invoke update-changes to have zero changes, got instead '"$(git diff CHANGES.rst)"'.
If you make a tag from this, it *will* error out.'
fi
-
name: Assert changelog in sync
if: ${{ github.ref_type == 'tag' }}
run: |
invoke update-changes
if ! git diff-index --quiet HEAD --
then
echo '::error file=CHANGES.rst,line=1,title=CHANGES.rst out of sync::Update the changelog.
Suggest you fix that and delete the tag.'
exit 254
fi
test_matrix:
needs: [verify_style, verify_types, update-changelog]
needs: [verify_style, verify_types, check-versions]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -148,85 +98,52 @@ jobs:
name: Install dependencies
run: |
python -m pip install --upgrade pip invoke typing-extensions
invoke setup --tests
invoke setup --devel --tests --no-project
invoke python-path
python/bin/python -m pip install -r setup-requirements.txt
-
name: Prepare build artifacts
run: |
invoke build --validate
python/bin/python -m pip install --no-index dist/instruct*.whl
-
name: Test with pytest
run: |
python/bin/python -m pytest
invoke test
pypi-publish:
needs: [test_matrix, verify_style, update-changelog]
check-versions:
runs-on: 'ubuntu-latest'
environment:
name: pypi
url: https://pypi.org/p/instruct
permissions:
id-token: write
contents: write
steps:
-
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

-
name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
architecture: 'x64'
-
name: Setup
run: |
python -m pip install --upgrade pip invoke typing-extensions
invoke setup --devel --no-project
-
name: Set some variables...
id: version
run: |
echo "CURRENT_VERSION=$(grep -vE '^#' CURRENT_VERSION.txt | head -1)" >> "$GITHUB_OUTPUT"
if [ "x${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') }}" = 'xtrue' ]; then
echo "GIT_VERSION=$(echo '${{ github.ref_name }}' | sed 's/^.//')" >> "$GITHUB_OUTPUT"
fi
echo "CHANGELOG_VERSION=$(invoke last-logged-changes | head -1 | cut -f2 -d' ')" >> "$GITHUB_OUTPUT"
-
name: Warn tag version matches the source version
if: ${{ github.ref_type != 'tag' }}
name: Warn if branch version already matches an existing tag
run: |
if [ 'x${{ steps.version.outputs.GIT_VERSION }}' != 'x${{ steps.version.outputs.CURRENT_VERSION }}' ]; then
echo '::warn file=CURRENT_VERSION.txt,line=2,title=Version mismatch::Expected ${{ steps.version.outputs.GIT_VERSION }} but got ${{ steps.version.outputs.CURRENT_VERSION }} instead.
If you make a tag from this, it *will* error out.'
if [ "x$(invoke local-tag-exists --format json 'v${{ steps.version.outputs.CURRENT_VERSION }}')" = 'xtrue' ]; then
echo '::warning file=CURRENT_VERSION.txt,line=2,title=Version already exists in tags::Tag v${{ steps.version.outputs.CURRENT_VERSION }} already exists.'
fi
-
name: Assert tag version matches the source version
if: ${{ github.ref_type == 'tag' }}
run: |
if [ 'x${{ steps.version.outputs.GIT_VERSION }}' != 'x${{ steps.version.outputs.CURRENT_VERSION }}' ]; then
echo '::error file=CURRENT_VERSION.txt,line=2,title=Version mismatch::Expected ${{ steps.version.outputs.GIT_VERSION }} but got ${{ steps.version.outputs.CURRENT_VERSION }} instead.
Suggest you fix that and delete the tag.'
exit 254
fi
-
name: Setup
run: |
python -m pip install --upgrade pip invoke typing-extensions
invoke setup --devel --no-project
-
name: Create artifacts
id: artifacts
run: |
invoke build --validate
invoke last_logged_changes | tee CHANGES.rst.${{ steps.version.outputs.CURRENT_VERSION }}
-
name: Create Release
if: ${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') }}
id: upload-release-asset
uses: softprops/action-gh-release@v1
with:
body_path: CHANGES.rst.${{ steps.version.outputs.CURRENT_VERSION }}
name: Release ${{ steps.version.outputs.CURRENT_VERSION }}
files:
dist/instruct*
# ARJ: disable for now
# -
# name: Publish package distributions to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# if: ${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') }}
# with:
# skip-existing: false
18 changes: 11 additions & 7 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ jobs:
name: Install dependencies
run: |
python -m pip install --upgrade pip invoke typing-extensions
invoke setup --tests
invoke setup --devel --tests --no-project
invoke python-path
python/bin/python -m pip install -r setup-requirements.txt
-
name: Prepare build artifacts
run: |
invoke build --validate
python/bin/python -m pip install --no-index dist/instruct*.whl
-
name: Test with pytest
run: |
python/bin/python -m pytest
invoke test
verify_style:
runs-on: 'ubuntu-latest'
Expand All @@ -78,14 +85,11 @@ jobs:
-
name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
python/bin/python -m flake8 instruct/ --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
python/bin/python -m flake8 instruct/ --ignore=E203,W503 --count --exit-zero --max-complexity=103 --max-line-length=127 --statistics
invoke lint
-
name: Check style with black
run: |
python/bin/python -m black --check instruct
invoke black --check
verify_types:
runs-on: 'ubuntu-latest'
Expand Down
Loading

0 comments on commit c1de740

Please sign in to comment.