From 4f73ce98d4dfddc8b4336794fab1b01bc0ead0cb Mon Sep 17 00:00:00 2001 From: fischor <21199007+fischor@users.noreply.github.com> Date: Fri, 27 Aug 2021 12:16:03 +0200 Subject: [PATCH] Setup actions for test, build and release (#7) Adds test, prepare-release and publish-pypi workflows. --- .github/RELEASE_TEMPLATE.md | 4 ++ .github/workflows/prepare-release.yaml | 85 ++++++++++++++++++++++++++ .github/workflows/publish-pypi.yaml | 52 ++++++++++++++++ .github/workflows/test.yaml | 69 +++++++++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 .github/RELEASE_TEMPLATE.md create mode 100644 .github/workflows/prepare-release.yaml create mode 100644 .github/workflows/publish-pypi.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/RELEASE_TEMPLATE.md b/.github/RELEASE_TEMPLATE.md new file mode 100644 index 0000000..4194414 --- /dev/null +++ b/.github/RELEASE_TEMPLATE.md @@ -0,0 +1,4 @@ +# Announcements +* First announcement + +# Changes \ No newline at end of file diff --git a/.github/workflows/prepare-release.yaml b/.github/workflows/prepare-release.yaml new file mode 100644 index 0000000..1490a7f --- /dev/null +++ b/.github/workflows/prepare-release.yaml @@ -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 }} diff --git a/.github/workflows/publish-pypi.yaml b/.github/workflows/publish-pypi.yaml new file mode 100644 index 0000000..df5a91e --- /dev/null +++ b/.github/workflows/publish-pypi.yaml @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..0267122 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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