Skip to content

Commit

Permalink
Merge pull request #58 from kjsanger/feature/conditional-release
Browse files Browse the repository at this point in the history
Make image deployment conditional on release
  • Loading branch information
kjsanger authored Apr 19, 2023
2 parents a6ec3ef + 56c5352 commit 8a17aa2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 41 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: "Create release"

on:
push:
tags:
- "*"

jobs:
release:
runs-on: ubuntu-latest

defaults:
run:
shell: bash -l -e -o pipefail {0}

steps:
- name: "Checkout code"
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: "Fetch Tags"
# Workaround for https://github.com/actions/checkout/issues/290
run: |
# Avoid git exiting when Actions runs
git config --global --add safe.directory "$PWD"
git fetch --tags --force
- name: "Get release variables"
run: |
echo 'RELEASE_VERSION='$(git describe --always --tags) >> $GITHUB_ENV
echo 'MASTER_SHA='$(git rev-parse origin/master) >> $GITHUB_ENV
- name: "Create Release"
uses: ncipollo/release-action@v1.12.0
with:
name: ${{ env.RELEASE_VERSION }}
prerelease: ${{ !(github.sha == env.MASTER_SHA) }}
generateReleaseNotes: true

outputs:
isRelease: ${{ github.sha == env.MASTER_SHA }}

deploy:
runs-on: ubuntu-latest

needs: release

# Workaround for https://github.com/actions/runner/issues/1483
# Actions coerces boolean to string
if: needs.release.outputs.isRelease == 'true'

steps:
- name: "Checkout code"
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: "Fetch Tags"
# Workaround for https://github.com/actions/checkout/issues/290
run: |
# Avoid git exiting when Actions runs
git config --global --add safe.directory "$PWD"
git fetch --tags --force
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug

- name: "Login to ghcr.io"
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: "Build and push Docker images"
run: |
cd docker
make GITHUB_ACTIONS=${GITHUB_ACTIONS} GITHUB_REPOSITORY_OWNER=${{ github.repository_owner }}
docker image prune --force
docker images
make push GITHUB_ACTIONS=${GITHUB_ACTIONS} GITHUB_REPOSITORY_OWNER=${{ github.repository_owner }}
41 changes: 0 additions & 41 deletions .github/workflows/push_container_image.yml

This file was deleted.

0 comments on commit 8a17aa2

Please sign in to comment.