Skip to content

Commit

Permalink
update image push workflow to create pr
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneknapp committed Oct 24, 2024
1 parent fb472aa commit fe52bbf
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Build and push container image, and push update to datahub repo if needed
on:
workflow_dispatch:
push:
branches:
- main
Expand Down Expand Up @@ -67,6 +68,10 @@ jobs:
update-deployment-image-tag:
runs-on: ubuntu-latest
needs: build-and-push
permissions:
contents: write
pull-requests: write
repository-projects: write
env:
HUB: ${{ vars.HUB }}
IMAGE: ${{ vars.IMAGE }}
Expand All @@ -92,15 +97,17 @@ jobs:
- name: Update the tag for any deployments that use this image
if: ${{ env.IMAGE_TAG }}
run: |
for deployment in $(grep -lr ${IMAGE} deployments/ | grep hubploy.yaml); do
for deployment in $(grep -lr ${IMAGE} deployments/); do
old_hash=$(grep ${IMAGE} ${deployment} | awk -F":" '{print $3}')
new_hash=${IMAGE_TAG}
sed -i -e "s,${IMAGE}:${old_hash},${IMAGE}:${new_hash},g" ${deployment}
echo "Updated ${deployment} with new image tag ${new_hash}"
done
- name: Create feature branch, add, commit and push changes
- name: Create feature branch, add, commit, push changes and open a pull request
if: ${{ env.IMAGE_TAG }}
env:
GH_TOKEN: ${{ secrets.DATAHUB_CREATE_PR }}
run: |
CHANGED_FILES=$(git status --porcelain -uno | awk '{print $2}')
git diff
Expand All @@ -109,8 +116,21 @@ jobs:
for file in $(echo -e ${CHANGED_FILES}); do
git add ${file}
done
git commit -m "update ${HUB} image tag to ${IMAGE_TAG}: ${CHANGED_FILES}"
git push origin update-${HUB}-image-tag-${IMAGE_TAG}
BRANCH="update-${HUB}-image-tag-${IMAGE_TAG}"
MESSAGE="update ${HUB} image tag to ${IMAGE_TAG}"
git commit -m "${MESSAGE}"
git push origin ${BRANCH}
#
# now create a PR!
#
cat << EOF > ${HOME}/pr-body.txt
${MESSAGE}
${CHANGED_FILES}
EOF
BODY=$(cat ${HOME}/pr-body.txt)
gh pr new -t "${MESSAGE}" -b "${BODY}" -H${BRANCH} -Bstaging
- name: Print out a message if no PR is created
if: ${{ ! env.IMAGE_TAG }}
Expand Down

0 comments on commit fe52bbf

Please sign in to comment.