Skip to content

Commit

Permalink
[DPE-2176] Improve checks on release workflow (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
deusebio committed Jun 27, 2023
1 parent 8ea6156 commit e590f0b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- id: tests-unit
name: Run Unittests
run: |
make unittest
make unittests
- id: tests-integration
name: Run Integration Tests
run: |
Expand Down
85 changes: 64 additions & 21 deletions .github/workflows/release_github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Create a github release for the spark8t Python library

env:
BRANCH: ${{ github.ref_name }}
VERSION: 0.0.1

on:
push:
Expand All @@ -11,23 +10,56 @@ on:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
code-checks:
uses: ./.github/workflows/ci-checks.yaml

release-checks:
tests:
uses: ./.github/workflows/ci-tests.yaml

release_checks:
name: Checks before pkg build
runs-on: ubuntu-latest
timeout-minutes: 5
needs: code-checks
strategy:
fail-fast: true
steps:
- id: version-vs-tag-check
- id: checkout
name: Checkout repo
uses: actions/checkout@v3
with:
ref: ${{ env.BRANCH }}
fetch-depth: 0
- id: setup_python
name: Setup Python
uses: actions/setup-python@v2.2.2
with:
python-version: '3.10'
architecture: x64
- id: install_environment
name: Set up build environment
run: |
make setup
- id: package_metadata
name: Fetch package metadata
run: |
NAME=$(poetry version | awk '{print $1}')
VERSION=$(poetry version | awk '{print $2}')
echo "name=$NAME" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- id: version_vs_tag_check
name: Check if tag version matches project version
run: |
VERSION=${{ steps.package_metadata.outputs.version }}
BRANCH=${{ env.BRANCH }}
if [[ "$BRANCH" != "v$VERSION" ]]; then exit 1; fi
outputs:
package_name: ${{ steps.package_metadata.outputs.name }}
package_version: ${{ steps.package_metadata.outputs.version }}

autorelease:
name: Release the package on github
needs: release-checks
needs: [release_checks, tests]
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
Expand All @@ -39,56 +71,67 @@ jobs:
with:
ref: ${{ env.BRANCH }}
fetch-depth: 0
- id: setup-python
- id: setup_python
name: Setup Python
uses: actions/setup-python@v2.2.2
with:
python-version: '3.10'
architecture: x64
- id: install-environment
- id: install_environment
name: Set up build environment
run: |
make setup
- id: build-package
- id: build_package
name: Build package
run: |
poetry build
- name: Add version to environment vars
- id: artifact_names
name: Compute artifact names outputs
run: |
echo "PROJECT_VERSION=${{ env.VERSION }}" >> $GITHUB_ENV
_NAME=${{ needs.release_checks.outputs.package_name }}
_VERSION=${{ needs.release_checks.outputs.package_version }}
echo "wheel=${_NAME}-${_VERSION}-py3-none-any.whl" >> "$GITHUB_OUTPUT"
echo "tarball=${_NAME}-${_VERSION}.tar.gz" >> "$GITHUB_OUTPUT"
- name: Create Github Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: ".github/RELEASE-TEMPLATE.md"
files: |
dist/spark8t-${{env.PROJECT_VERSION}}-py3-none-any.whl
dist/spark8t-${{env.PROJECT_VERSION}}.tar.gz
dist/${{ steps.artifact_names.outputs.wheel }}
dist/${{ steps.artifact_names.outputs.tarball }}
outputs:
version: ${{ needs.release_checks.outputs.package_version }}
wheel: ${{ steps.artifact_names.outputs.wheel }}
tarball: ${{ steps.artifact_names.outputs.tarball }}

test:
name: Test Release
runs-on: ubuntu-latest
timeout-minutes: 5
env:
DOWNLOADS_PATH: "/releases/download"
PKG_NAME: spark8t
needs: autorelease
needs: [autorelease]
steps:
- id: check-tar-gz
name: Check tar.gz package
run: |
# check if release is now published and available
echo "Checking latest available Spark package release v${{env.VERSION}}."
STATUSCODE=$(curl --silent --head $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${{env.VERSION}}/${{env.PKG_NAME}}-${{env.VERSION}}.tar.gz | head -n 1 | cut -d' ' -f2)
TARBALL=${{ needs.autorelease.outputs.tarball }}
VERSION=${{ needs.autorelease.outputs.version }}
echo "Checking latest available Spark package release: ${TARBALL}"
STATUSCODE=$(curl --silent --head $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${VERSION}/${TARBALL} | head -n 1 | cut -d' ' -f2)
if [[ ${STATUSCODE} -ne 200 ]] && [[ ${STATUSCODE} -ne 302 ]]; then exit 1; fi
- id: download-package
name: Download wheel package
run: |
# check if release is now published and available
echo "Downloading latest available Spark wheel package release v${{env.VERSION}}."
wget $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${{env.VERSION}}/${{env.PKG_NAME}}-${{env.VERSION}}-py3-none-any.whl --no-check-certificate
WHEEL=${{ needs.autorelease.outputs.wheel }}
VERSION=${{ needs.autorelease.outputs.version }}
echo "Downloading latest available Spark wheel package release ${WHEEL}."
wget $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${VERSION}/${WHEEL} --no-check-certificate
- id: install-package
name: Install wheel package file
run: |
pip install ./${{env.PKG_NAME}}-${{env.VERSION}}-py3-none-any.whl
pip install ./${{ needs.autorelease.outputs.wheel }}
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PYTHON = poetry run

# .PHONY defines parts of the makefile that are not dependant on any specific file
# This is most often used to store functions
.PHONY = help setup format build install uninstall checks unittest integration-test clean
.PHONY: help setup format checks unittests integration-tests clean

folders := helpers tests
files := $(shell find . -name "*.py")
Expand Down Expand Up @@ -38,8 +38,8 @@ help:
@echo " - setup for installing base requirements"
@echo " - format for reformatting files to adhere to PEP8 standards"
@echo " - checks for running format, mypy, lint and tests altogether"
@echo " - unittest for running unittests"
@echo " - integration-test for running integration tests"
@echo " - unittests for running unittests"
@echo " - integration-tests for running integration tests"
@echo " - clean for removing cache file"
@echo "------------------------------------"

Expand Down Expand Up @@ -73,7 +73,7 @@ requirements.txt: poetry.lock pyproject.toml
format: setup $(files)
${PYTHON} tox -e fmt

unittest: setup $(files)
unittests: setup $(files)
${PYTHON} tox -e unit

$(checks_tag): $(setup_tag)
Expand Down

0 comments on commit e590f0b

Please sign in to comment.