Skip to content

Commit

Permalink
Merge pull request #1212 from alphagov/add-create-pr
Browse files Browse the repository at this point in the history
Add create-pr yaml and sh
  • Loading branch information
kentsanggds authored Nov 21, 2023
2 parents 09b9250 + d57f4b0 commit 2ee5d66
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/create-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Create charts PR

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

jobs:
create_pr:
name: Create charts PR
runs-on: ubuntu-latest
steps:
- name: Checkout datagovuk_publish repository
uses: actions/checkout@v4
with:
repository: alphagov/datagovuk_publish
path: ckanext
- run: bash ./docker/create-pr.sh
env:
GH_TOKEN: ${{ secrets.PR_GITHUB_TOKEN }}
GH_REF: ${{ github.ref_name }}
IS_TAG: "false"
ENVS: "integration"
45 changes: 45 additions & 0 deletions docker/create-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -eux

if [[ ${IS_TAG:-} = "true" ]]; then
export IMAGE_TAG="${GH_REF}"
export SOURCE_BRANCH="main"
else
export IMAGE_TAG=$(gh api repos/alphagov/datagovuk_publish/branches/${GH_REF} | jq .commit.sha -r)
export SOURCE_BRANCH=${GH_REF}
fi

git config --global user.email "[email protected]"
git config --global user.name "govuk-ci"

git clone https://${GH_TOKEN}@github.com/alphagov/govuk-dgu-charts.git charts

cd charts/charts/datagovuk/images

for ENV in $(echo $ENVS | tr "," " "); do
(
BRANCH="ci/${IMAGE_TAG}-${ENV}"

if git show-ref --quiet refs/heads/${BRANCH}; then
echo "Branch ${BRANCH} already exists on govuk-dgu-charts"
else
git checkout -b ${BRANCH}

cd "${ENV}"
for APP in ckan pycsw solr; do
yq -i '.tag = env(IMAGE_TAG)' "${APP}.yaml"
yq -i '.branch = env(SOURCE_BRANCH)' "${APP}.yaml"
git add "${APP}.yaml"
done

if [[ $(git status | grep "nothing to commit") ]]; then
echo "Nothing to commit"
else
git commit -m "Update image tags for ${ENV} to ${IMAGE_TAG}"
git push --set-upstream origin "${BRANCH}"
gh pr create --title "Update image tags for ${ENV} (${IMAGE_TAG})" --base main --head "${BRANCH}" --fill
fi
fi
)
done

0 comments on commit 2ee5d66

Please sign in to comment.