From 74ce83994fc90f802cbc3584a95628afa4a11452 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 13 Feb 2024 13:46:24 -0500 Subject: [PATCH 1/3] rename workflow files --- .../workflows/{pull-request-received.yml => pull_request.yml} | 2 +- .github/workflows/{build-pipeline.yml => push.yml} | 2 +- .github/workflows/{reusable_run_tests.yml => run_tests.yml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{pull-request-received.yml => pull_request.yml} (83%) rename .github/workflows/{build-pipeline.yml => push.yml} (98%) rename .github/workflows/{reusable_run_tests.yml => run_tests.yml} (100%) diff --git a/.github/workflows/pull-request-received.yml b/.github/workflows/pull_request.yml similarity index 83% rename from .github/workflows/pull-request-received.yml rename to .github/workflows/pull_request.yml index fbfe8c5..3bb60c9 100644 --- a/.github/workflows/pull-request-received.yml +++ b/.github/workflows/pull_request.yml @@ -10,4 +10,4 @@ on: jobs: build_and_test: - uses: ./.github/workflows/reusable_run_tests.yml + uses: ./.github/workflows/run_tests.yml diff --git a/.github/workflows/build-pipeline.yml b/.github/workflows/push.yml similarity index 98% rename from .github/workflows/build-pipeline.yml rename to .github/workflows/push.yml index e312d94..6df6f30 100644 --- a/.github/workflows/build-pipeline.yml +++ b/.github/workflows/push.yml @@ -13,7 +13,7 @@ on: jobs: run_tests: - uses: ./.github/workflows/reusable_run_tests.yml + uses: ./.github/workflows/run_tests.yml bump_version: needs: run_tests diff --git a/.github/workflows/reusable_run_tests.yml b/.github/workflows/run_tests.yml similarity index 100% rename from .github/workflows/reusable_run_tests.yml rename to .github/workflows/run_tests.yml From 244cae416ad1dc551c53f1a4ff4ed60d78706c97 Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Tue, 13 Feb 2024 13:49:12 -0500 Subject: [PATCH 2/3] add steps to push package to container registry --- .github/workflows/push.yml | 152 ++++++++++++++++++++++++++----------- 1 file changed, 106 insertions(+), 46 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 6df6f30..f39dfc8 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -11,6 +11,12 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +env: + POETRY_VERSION: "1.3.2" + PYTHON_VERSION: "3.10" + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: run_tests: uses: ./.github/workflows/run_tests.yml @@ -24,12 +30,12 @@ jobs: - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: ${{ env.PYTHON_VERSION }} - name: Install Poetry uses: abatilo/actions-poetry@v3.0.0 with: - poetry-version: 1.3.2 + poetry-version: ${{ env.POETRY_VERSION }} - name: Get version id: get-version @@ -37,51 +43,105 @@ jobs: echo "current_version=$(poetry version | awk '{print $2}')" >> $GITHUB_OUTPUT echo "pyproject_name=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV -# - name: Bump pre-alpha version -# # If triggered by push to a feature branch -# if: | -# ${{ startsWith(github.ref, 'refs/heads/issue') }} || -# ${{ startsWith(github.ref, 'refs/heads/dependabot/') }} || -# ${{ startsWith(github.ref, 'refs/heads/feature/') }} -# run: | -# new_ver="${{ steps.get-version.outputs.current_version }}+$(git rev-parse --short ${GITHUB_SHA})" -# poetry version $new_ver -# echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV -# -# - name: Bump alpha version -# # If triggered by push to the develop branch -# if: ${{ github.ref == 'refs/heads/develop' }} -# run: | -# poetry version prerelease -# echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV -# echo "venue=sit" >> $GITHUB_ENV -# -# - name: Bump rc version -# # If triggered by push to a release branch -# if: ${{ startsWith(github.ref, 'refs/heads/release/') }} -# env: -# # True if the version already has a 'rc' pre-release identifier -# BUMP_RC: ${{ contains(steps.get-version.outputs.current_version, 'rc') }} -# run: | -# if [ "$BUMP_RC" = true ]; then -# poetry version prerelease -# else -# poetry version ${GITHUB_REF#refs/heads/release/}rc1 -# fi -# echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV -# echo "venue=uat" >> $GITHUB_ENV -# -# - name: Release version -# # If triggered by push to the main branch -# if: ${{ startsWith(github.ref, 'refs/heads/main') }} -# env: -# CURRENT_VERSION: ${{ steps.get-version.outputs.current_version }} -# # Remove rc* from the end of version string -# # The ${string%%substring} syntax below deletes the longest match of $substring from back of $string. + - name: Bump pre-alpha version + # If triggered by push to a feature branch + if: | + ${{ startsWith(github.ref, 'refs/heads/issue') }} || + ${{ startsWith(github.ref, 'refs/heads/dependabot/') }} || + ${{ startsWith(github.ref, 'refs/heads/feature/') }} + run: | + new_ver="${{ steps.get-version.outputs.current_version }}+$(git rev-parse --short ${GITHUB_SHA})" + poetry version $new_ver + echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV + + - name: Bump alpha version + # If triggered by push to the develop branch + if: ${{ github.ref == 'refs/heads/develop' }} + run: | + poetry version prerelease + echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV + echo "venue=sit" >> $GITHUB_ENV + + - name: Bump rc version + # If triggered by push to a release branch + if: ${{ startsWith(github.ref, 'refs/heads/release/') }} + env: + # True if the version already has a 'rc' pre-release identifier + BUMP_RC: ${{ contains(steps.get-version.outputs.current_version, 'rc') }} + run: | + if [ "$BUMP_RC" = true ]; then + poetry version prerelease + else + poetry version ${GITHUB_REF#refs/heads/release/}rc1 + fi + echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV + echo "venue=uat" >> $GITHUB_ENV + + - name: Release version + # If triggered by push to the main branch + if: ${{ startsWith(github.ref, 'refs/heads/main') }} + env: + CURRENT_VERSION: ${{ steps.get-version.outputs.current_version }} + # True if the version already has a 'rc' pre-release identifier + BUMP_RC: ${{ contains(steps.get-version.outputs.current_version, 'rc') }} + # True if the version already has an 'alpha' pre-release identifier + BUMP_A: ${{ contains(steps.get-version.outputs.current_version, 'a') }} + # True if the version already has a 'beta' pre-release identifier + BUMP_B: ${{ contains(steps.get-version.outputs.current_version, 'b') }} + # Remove rc* from the end of version string + # The ${string%%substring} syntax below deletes the longest match of $substring from back of $string. + run: | + if [ "$BUMP_RC" = true ]; then + poetry version ${CURRENT_VERSION%%rc*} + elif [ "$BUMP_B" = true ]; then + poetry version ${CURRENT_VERSION%%b*} + elif [ "$BUMP_A" = true ]; then + poetry version ${CURRENT_VERSION%%a*} + fi + echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV + echo "venue=ops" >> $GITHUB_ENV + + - name: Log in to the Container registry + # TODO: change this and subsequent docker steps back to NOT (as follows), after testing in the feature branch --- if: ${{ !startsWith(github.ref, 'refs/heads/feature') }} + if: ${{ startsWith(github.ref, 'refs/heads/feature/') }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker +# if: ${{ !startsWith(github.ref, 'refs/heads/feature') }} + if: ${{ startsWith(github.ref, 'refs/heads/feature/') }} + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,pattern={{version}},value=${{ env.software_version }} + type=raw,value=${{ env.venue }} + +# - name: Wait for package +## if: ${{ !startsWith(github.ref, 'refs/heads/feature') }} +# if: ${{ startsWith(github.ref, 'refs/heads/feature/') }} # run: | -# poetry version ${CURRENT_VERSION%%rc*} -# echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV -# echo "venue=ops" >> $GITHUB_ENV +# pip install tenacity +# ${GITHUB_WORKSPACE}/.github/workflows/wait-for-pypi.py ${{env.pyproject_name}}[harmony]==${{ env.software_version }} + + - name: Build and push Docker image +# if: ${{ !startsWith(github.ref, 'refs/heads/feature') }} + if: ${{ startsWith(github.ref, 'refs/heads/feature/') }} + id: docker-push + uses: docker/build-push-action@v3 + with: + context: . + file: Dockerfile + build-args: | + SOURCE=${{env.pyproject_name}}[harmony]==${{ env.software_version }} + push: true + pull: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} # # - name: Commit Version Bump # # If building develop, a release branch, or main then we commit the version bump back to the repo From 3ccc7cbafe599c0a53e461eeb646a81b0b3eb3ae Mon Sep 17 00:00:00 2001 From: danielfromearth Date: Mon, 4 Mar 2024 14:56:19 -0500 Subject: [PATCH 3/3] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a60abf6..d2a5c5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [issue/7](https://github.com/danielfromearth/batchee/issues/7): Create working Docker image - [issue/13](https://github.com/danielfromearth/batchee/issues/13): Add simple command line interface for testing - [issue/16](https://github.com/danielfromearth/batchee/issues/16): Add a logo +- [PR #75](https://github.com/danielfromearth/batchee/pull/75): Add Docker build steps to GitHub Actions workflow ### Changed - [issue/11](https://github.com/danielfromearth/batchee/issues/11): Rename from concat_batcher to batchee - [issue/21](https://github.com/danielfromearth/batchee/issues/21): Improve CICD workflows