Skip to content

Commit

Permalink
Merge pull request #1193 from alphagov/add-build-and-create-pr-on-tags
Browse files Browse the repository at this point in the history
Add build-image-on-tags and create-pr-on-tags actions
  • Loading branch information
nimalank7 authored Nov 22, 2023
2 parents dc0ad2a + 4bca319 commit 2c50868
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build-image-on-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and push images on tags

on:
push:
tags:
- 'k[0-9]+.[0-9]+.[0-9]+'

jobs:
build_and_push:
name: datagovuk_find
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Login to GHCR
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
with:
ref: ${{ inputs.gitRef }}
- name: Build and push images
env:
APP: datagovuk_find
ARCH: amd64
GH_REF: ${{ github.ref_name }}
run: ./docker/build-image.sh
23 changes: 23 additions & 0 deletions .github/workflows/create-pr-on-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Create charts PR on tags creation

on:
workflow_dispatch:
workflow_run:
workflows: [ "Build and push images on tags" ]
types:
- completed

jobs:
create_pr:
name: Create charts PR on tags creation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set GH_REF
# Change back to git tag once we no longer need the k versions
run: echo "GH_REF=`echo $(git fetch -t -q && git tag -l "k*" | sort --version-sort | tail -n1)`" >> $GITHUB_ENV
- run: bash ./docker/create-pr.sh
env:
GH_TOKEN: ${{ secrets.PR_GITHUB_TOKEN }}
IS_TAG: "true"
ENVS: "staging,production"
4 changes: 4 additions & 0 deletions docker/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ build () {

DOCKER_TAG="${GITHUB_SHA}"

if [[ -n ${GH_REF:-} ]]; then
DOCKER_TAG="${GH_REF}"
fi

build "${DOCKER_TAG}"

if [[ -n ${DRY_RUN:-} ]]; then
Expand Down

0 comments on commit 2c50868

Please sign in to comment.