From 4bca31937cb42b62561723f5e380e847b0605609 Mon Sep 17 00:00:00 2001 From: nimalank7 Date: Wed, 22 Nov 2023 12:14:42 +0000 Subject: [PATCH] Add build-image-on-tags and create-pr-on-tags actions Description: - Add action to build docker image when a tag is pushed - Add action to create a PR against govuk-dgu-charts repo once the build-image-on-tags pipeline is completed --- .github/workflows/build-image-on-tags.yaml | 29 ++++++++++++++++++++++ .github/workflows/create-pr-on-tags.yaml | 23 +++++++++++++++++ docker/build-image.sh | 4 +++ 3 files changed, 56 insertions(+) create mode 100644 .github/workflows/build-image-on-tags.yaml create mode 100644 .github/workflows/create-pr-on-tags.yaml diff --git a/.github/workflows/build-image-on-tags.yaml b/.github/workflows/build-image-on-tags.yaml new file mode 100644 index 00000000..9adcc2b0 --- /dev/null +++ b/.github/workflows/build-image-on-tags.yaml @@ -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 diff --git a/.github/workflows/create-pr-on-tags.yaml b/.github/workflows/create-pr-on-tags.yaml new file mode 100644 index 00000000..c2109d8e --- /dev/null +++ b/.github/workflows/create-pr-on-tags.yaml @@ -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" diff --git a/docker/build-image.sh b/docker/build-image.sh index 131443df..62bd8f67 100755 --- a/docker/build-image.sh +++ b/docker/build-image.sh @@ -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