Skip to content

Commit

Permalink
Update GitHub Actions for new packaging
Browse files Browse the repository at this point in the history
This also separates the workflows  into reusable ones to prevent code duplication.
  • Loading branch information
mhostetter committed Aug 20, 2022
1 parent 8ac3da3 commit 6beb19b
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 268 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build

on:
workflow_call

jobs:
build_wheel:
name: Wheel
runs-on: ubuntu-latest
outputs:
wheel_file: ${{ steps.get_wheel_name.outputs.paths }}
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Upgrade pip and other packaging tools
run: python3 -m pip install --upgrade pip setuptools wheel build twine

- name: Build the `galois` package
run: python3 -m build

- name: Verify the wheel file
run: python3 -m twine check dist/*

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/
retention-days: 1
31 changes: 12 additions & 19 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
name: Docs

on:
# push:
# branches:
# - master
pull_request:
branches:
- master
workflow_call

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install documentation dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r docs/requirements.txt
- name: Upgrade pip
run: python3 -m pip install --upgrade pip

- name: Install Python package
run: python3 -m pip install .
- name: Install the `galois` package with [doc]
run: python3 -m pip install .[doc]

- name: Run Sphinx to build docs
run: sphinx-build -b dirhtml -v docs/ docs/build/
- name: Run Sphinx to build docs
run: sphinx-build -b dirhtml -v docs/ docs/build/
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint

on:
workflow_call

jobs:
run-linter:
name: Run
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10']
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade pip
run: python3 -m pip install --upgrade pip

- name: Install the `galois` package with [dev]
run: python3 -m pip install .[dev]

- name: Lint with pylint
run: python3 -m pylint src/galois/
23 changes: 23 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pull Request

on:
# push:
# branches:
# - master
pull_request:
branches:
- master

jobs:
build:
uses: ./.github/workflows/build.yml

lint:
uses: ./.github/workflows/lint.yml

docs:
uses: ./.github/workflows/docs.yml

test:
uses: ./.github/workflows/test.yml
needs: build
172 changes: 99 additions & 73 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,118 @@ on:
release_type:
description: "Release type (major,minor,patch)"
required: true
type: string
default: "patch"

jobs:
release:
name: Create new release
tag:
name: Tag new version
id: tag
runs-on: ubuntu-latest
outputs:
previous_version: ${{ steps.previous_version.outputs.version }}
next_version: ${{ steps.next_version.outputs.version }}
steps:
- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: 3.7
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all commits and tags
ref: ${{ github.REF }}

- name: Set up Python 3
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Get previous version
id: previous_version
run: | # Get last version tag and remove the "v"
version=$(git describe --tags --abbrev=0 | cut -c 2-)
echo "::set-output name=version::${version}"
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all commits and tags
ref: ${{ github.REF }}
- name: Validate next version
uses: zwaldowski/semver-release-action@v2
id: next_version
with:
dry_run: true
bump: ${{ github.event.inputs.release_type }}
prefix: "v"
github_token: ${{ secrets.GITHUB_TOKEN }}

# - name: Wait on other workflows
# uses: lewagon/wait-on-check-action@v0.2
# with:
# ref: ${{ github.REF }}
# repo-token: ${{ secrets.GITHUB_TOKEN }}
# wait-interval: 5
# - name: Update version file
# run: |
# echo -n "${{ steps.next_version.outputs.version }}" > galois/version.txt
# cat galois/version.txt

- name: Get previous version
id: previous_version
run: | # Get last version tag and remove the "v"
version=$(git describe --tags --abbrev=0 | cut -c 2-)
echo "::set-output name=version::${version}"
- name: Create and push new tag
uses: rickstaa/action-create-tag@v1
with:
tag: "v${{ steps.next_version.outputs.version }}"
message: "v${{ steps.next_version.outputs.version }}"

- name: Validate next version
uses: zwaldowski/semver-release-action@v2
id: next_version
with:
dry_run: true
bump: ${{ github.event.inputs.release_type }}
prefix: "v"
github_token: ${{ secrets.GITHUB_TOKEN }}
# - name: Commit and tag version
# uses: stefanzweifel/git-auto-commit-action@v4
# with:
# file_pattern: galois/version.txt
# commit_message: "Version bump to ${{ steps.next_version.outputs.version }}"
# repository: .
# branch: master
# tagging_message: "v${{ steps.next_version.outputs.version }}"

- name: Update version file
run: |
echo -n "${{ steps.next_version.outputs.version }}" > galois/version.txt
cat galois/version.txt
build:
name: Build the package
id: build
needs: tag
uses: ./.github/workflows/build.yml

- name: Commit and tag version
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: galois/version.txt
commit_message: "Version bump to ${{ steps.next_version.outputs.version }}"
repository: .
branch: master
tagging_message: "v${{ steps.next_version.outputs.version }}"
release-test:
name: Release on TestPyPI
id: release-test
needs: build
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all commits and tags
ref: ${{ github.REF }}

- uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all commits and tags
ref: ${{ github.REF }}
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
verbose: true

- name: Construct release notes
run: |
prev=v${{ steps.previous_version.outputs.version }}
next=v${{ steps.next_version.outputs.version }}
echo -e "\n## Contributors" > release_notes.md
git log ${prev}..${next} --pretty="- @%an" | sort | uniq >> release_notes.md
echo -e "\n## Commits" >> release_notes.md
git log --oneline ${prev}..${next} >> release_notes.md
release:
name: Release on PyPI
id: release
needs: tag, release-test
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all commits and tags
ref: ${{ github.REF }}

- name: Create GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.next_version.outputs.version }}
release_name: galois v${{ steps.next_version.outputs.version }}
body_path: release_notes.md
draft: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true

- name: Build Python package
run: |
python3 -m pip install --upgrade setuptools wheel twine
python3 setup.py sdist bdist_wheel
python3 -m twine check dist/*
- name: Construct release notes
run: |
prev=v${{ needs.tag.outputs.previous_version }}
next=v${{ needs.tag.outputs.next_version }}
cp docs/release-notes/v${{ needs.tag.outputs.next_version }}.md release_notes.md
echo -e "\n## Commits" >> release_notes.md
git log --oneline ${prev}..${next} >> release_notes.md
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.4.2
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true
- name: Create GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.tag.outputs.version }}
release_name: galois v${{ needs.tag.outputs.version }}
body_path: release_notes.md
draft: true
Loading

0 comments on commit 6beb19b

Please sign in to comment.