diff --git a/.github/workflows/publish-build.yml b/.github/workflows/publish-build.yml new file mode 100755 index 0000000..2b7b466 --- /dev/null +++ b/.github/workflows/publish-build.yml @@ -0,0 +1,31 @@ +name: Validate Build + +on: + release: + types: [published,prereleased] + +jobs: + + publish: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: | + export DOCKER_IMAGE=mtconnect-python:$(date +%s) + echo "DOCKER_IMAGE=${DOCKER_IMAGE}" >> $GITHUB_ENV + docker build . --file Dockerfile --tag ${DOCKER_IMAGE} + - name: Bump Version + run: | + ./scripts/run_container.sh ${DOCKER_IMAGE} scripts/set_version.sh ${{ GITHUB_REF }} + echo "VERSION_CHANGE=$(git diff --exit-code)" >> $GITHUB_ENV + - name: Commit Change + if: ${{ vars.VERSION_CHANGE == '1' }} + run: | + git add . + git commit -m 'Bump Version' + git tag -d ${{ GITHUB_REF }} + git tag ${{ GITHUB_REF }} + git push --force origin ${{ GITHUB_REF }} \ No newline at end of file diff --git a/.github/workflows/validate-build.yml b/.github/workflows/validate-build.yml new file mode 100644 index 0000000..8656e93 --- /dev/null +++ b/.github/workflows/validate-build.yml @@ -0,0 +1,25 @@ +name: Validate Build + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + validate: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: | + export DOCKER_IMAGE=mtconnect-python:$(date +%s) + echo "DOCKER_IMAGE=${DOCKER_IMAGE}" >> $GITHUB_ENV + docker build . --file Dockerfile --tag ${DOCKER_IMAGE} + - name: Test Format + run: ./scripts/run_container.sh ${DOCKER_IMAGE} scripts/format_package.sh --check + - name: Test Package + run: ./scripts/run_container.sh ${DOCKER_IMAGE} scripts/test_package.sh \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 4b0a745..db335fb 100755 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,10 @@ FROM python:3.8-slim as base WORKDIR /data -# Install poetry -RUN pip3 install poetry +# Install deps +RUN pip3 install poetry && \ + apt update && \ + apt install git -y # Copy depdencies and install base packages COPY pyproject.toml poetry.lock ./ diff --git a/Makefile b/Makefile index 5f2b3bf..842da25 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,29 @@ build: develop: build ./scripts/run_develop_container.sh ${IMAGE_NAME} bash +run: build + ./scripts/run_container.sh ${IMAGE_NAME} bash + test: build ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/test_package.sh +test.format: build + ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/format_package.sh --check + + format: build ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/format_package.sh + lint: build - ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/lint_package.sh + ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/lint_package.sh PYPI_USER?=${PYPI_USER} PYPI_PASSWORD?=${PYPI_PASSWORD} publish: build - ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/publish_package.sh \ No newline at end of file + ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/publish_package.sh + +# This is only here for completeness. This should only be called via CI +VERSION?=${VERSION} +version: build + ./scripts/run_develop_container.sh ${IMAGE_NAME} scripts/set_version.sh ${VERSION} \ No newline at end of file diff --git a/scripts/format_package.sh b/scripts/format_package.sh index a953a75..363b6f0 100755 --- a/scripts/format_package.sh +++ b/scripts/format_package.sh @@ -1,3 +1,3 @@ #!/bin/bash -python3 -m black . \ No newline at end of file +python3 -m black . "$@" \ No newline at end of file diff --git a/scripts/lint_package.sh b/scripts/lint_package.sh index a958b04..fa24d57 100755 --- a/scripts/lint_package.sh +++ b/scripts/lint_package.sh @@ -1,3 +1,3 @@ #!/bin/bash -python3 -m pylint mtconnect tests \ No newline at end of file +python3 -m pylint mtconnect tests "$@" \ No newline at end of file diff --git a/scripts/run_container.sh b/scripts/run_container.sh new file mode 100755 index 0000000..fe4af55 --- /dev/null +++ b/scripts/run_container.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ "$#" -lt 2 ]; then + echo "Please supply image name and command to run" + exit 1 +fi + +image_name=$1 + +docker run --name run-ctr --rm ${image_name} "${@:2}" \ No newline at end of file diff --git a/scripts/set_version.sh b/scripts/set_version.sh new file mode 100755 index 0000000..3fc34ac --- /dev/null +++ b/scripts/set_version.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Please supply version" + exit 1 +fi + +poetry version "$@" \ No newline at end of file diff --git a/scripts/test_package.sh b/scripts/test_package.sh index 0e022aa..f102c1b 100755 --- a/scripts/test_package.sh +++ b/scripts/test_package.sh @@ -1,3 +1,3 @@ #!/bin/bash -python3 -m unittest \ No newline at end of file +python3 -m unittest "$@" \ No newline at end of file