Skip to content

Commit

Permalink
Configure Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
HonakerM committed Jan 11, 2023
1 parent b18f838 commit a503b3e
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 7 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/publish-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish Build

on:
release:
types: [published]
push:
# support traditional versions, and dev versions
tags: ["*.*.*","*.*.*-*"]

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_NAME}"
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_NAME}
git tag ${GITHUB_REF_NAME}
git push --force origin ${GITHUB_REF_NAME}
25 changes: 25 additions & 0 deletions .github/workflows/validate-build.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./
Expand Down
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
./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}
2 changes: 1 addition & 1 deletion scripts/format_package.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

python3 -m black .
python3 -m black . "$@"
2 changes: 1 addition & 1 deletion scripts/lint_package.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

python3 -m pylint mtconnect tests
python3 -m pylint mtconnect tests "$@"
10 changes: 10 additions & 0 deletions scripts/run_container.sh
Original file line number Diff line number Diff line change
@@ -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}"
8 changes: 8 additions & 0 deletions scripts/set_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
echo "Please supply version"
exit 1
fi

poetry version "$@"
2 changes: 1 addition & 1 deletion scripts/test_package.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

python3 -m unittest
python3 -m unittest "$@"

0 comments on commit a503b3e

Please sign in to comment.