Skip to content

Commit

Permalink
Setup actions for test, build and release (#7)
Browse files Browse the repository at this point in the history
Adds test, prepare-release and publish-pypi workflows.
  • Loading branch information
fischor authored Aug 27, 2021
1 parent 7737ddc commit 4f73ce9
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/RELEASE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Announcements
* First announcement

# Changes
85 changes: 85 additions & 0 deletions .github/workflows/prepare-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
on:
push:
tags:
- "v*.*.*"

name: Prepare Release

jobs:
autorelease:
name: Prepare Release
runs-on: "ubuntu-latest"
steps:
- name: Checkout code
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v2.2.2
with:
python-version: "3.8"
- name: python --version
run: |
python --version
python3 --version
- name: Setup protoc
uses: arduino/setup-protoc@v1
with:
version: "3.17.3"
- name: protoc --version
run: protoc --version
- name: Permacache Poetry
id: cache-poetry
uses: actions/cache@v2.1.6
with:
path: ~/.poetry
key: poetry
- name: Install latest version of Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
- name: Add Poetry to $PATH
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Add version to environment vars
run: |
PROJECT_VERSION=$(poetry version --short)
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
- name: Check if tag version matches project version
run: |
TAG=$(git describe HEAD --tags --abbrev=0)
echo $TAG
echo $PROJECT_VERSION
if [[ "$TAG" != "v$PROJECT_VERSION" ]]; then exit 1; fi
- name: poetry --version
run: poetry --version
- name: Check pyproject.toml validity
run: poetry check --no-interaction
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2.1.6
with:
path: ${{github.workspace}}/.venv
key: poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: poetry-
- name: Install deps
if: steps.cache-deps.cache-hit != 'true'
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction
- name: Run tests
run: poetry run python -m unittest test.test_protogen
- name: Build
run: poetry build
- name: Release Notes
run: git log $(git describe HEAD~ --tags --abbrev=0)..HEAD --pretty='format:* %h %s%n * %an <%ae>' --no-merges >> ".github/RELEASE-TEMPLATE.md"
- name: Create Release Draft
uses: softprops/action-gh-release@v1
with:
body_path: ".github/RELEASE-TEMPLATE.md"
draft: true
files: |
dist/protogen-${{env.PROJECT_VERSION}}-py3-none-any.whl
dist/protogen-${{env.PROJECT_VERSION}}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 52 additions & 0 deletions .github/workflows/publish-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
on:
release:
types:
- published

name: PyPI Publish

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2.3.4
- name: Setup Python
uses: actions/setup-python@v2.2.2
with:
python-version: "3.8"
- name: Permacache Poetry
id: cache-poetry
uses: actions/cache@v2.1.6
with:
path: ~/.poetry
key: poetry
- name: Install latest version of Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
- name: Add Poetry to $PATH
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Get Poetry version
run: poetry --version
- name: Check pyproject.toml validity
run: poetry check --no-interaction
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2.1.6
with:
path: ${{github.workspace}}/.venv
key: poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: poetry-
- name: Install deps
if: steps.cache-deps.cache-hit != 'true'
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction
- name: Publish to PyPI
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
69 changes: 69 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
on:
push:
branches: [main, actions]
pull_request:
branches: [main, actions]

name: Test

defaults:
run:
shell: bash

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2.3.4
- name: Setup Python
uses: actions/setup-python@v2.2.2
with:
python-version: 3.8
- name: python --version
run: |
python --version
python3 --version
- name: Setup protoc
uses: arduino/setup-protoc@v1
with:
version: "3.17.3"
- name: protoc --version
run: protoc --version
# Perma-cache Poetry since we only need it for checking pyproject version
- name: Cache Poetry
id: cache-poetry
uses: actions/cache@v2.1.6
with:
path: ~/.poetry
key: poetry
# Only runs when key from caching step changes
- name: Install latest version of Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
# Poetry still needs to be re-prepended to the PATH on each run, since
# PATH does not persist between runs.
- name: Add Poetry to $PATH
run: |
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Get Poetry version
run: poetry --version
- name: Check pyproject.toml validity
run: poetry check --no-interaction
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2.1.6
with:
path: ${{github.workspace}}/.venv
key: deps-${{ hashFiles('**/poetry.lock') }}
- name: Install deps
if: steps.cache-deps.cache-hit != 'true'
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction
- name: Run tests
run: poetry run python -m unittest test.test_protogen
- name: Build artifacts
run: poetry build

0 comments on commit 4f73ce9

Please # to comment.