Skip to content

Commit

Permalink
create PR workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneknapp committed Jul 29, 2024
1 parent a02e39f commit b42da87
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
File renamed without changes.
61 changes: 49 additions & 12 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and push container image
name: Build and push container image, open PR if needed
# try to follow the example here: https://gist.github.com/Daniel-ltw/552b90800b07c22e4a83dfa68ada6318
on:
push:
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Log in to GAR
if: steps.changed-files.outputs.any_changed == 'true'
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: us-central1-docker.pkg.dev
username: _json_key
Expand Down Expand Up @@ -74,33 +74,70 @@ jobs:
HUB: ${{ vars.HUB }}
IMAGE: ${{ vars.IMAGE }}
steps:
- name: print the hash
- name: store the image tag in an env variable
run: |
echo $IMAGE_TAG
echo ${{ needs.build-and-push.outputs.image-tag }}
echo "IMAGE_TAG=${{ needs.build-and-push.outputs.image-tag }}" >> $GITHUB_ENV
- name: logic test to see if we should create a PR
id: set-create-pr
run: |
if [ -z "$IMAGE_TAG" ]; then
echo "CREATE_PR=false" >> $GITHUB_ENV
echo "::set-output name=create_pr::false"
else
echo "CREATE_PR=true" >> $GITHUB_ENV
echo "::set-output name=create_pr::true"
fi
- name: Checkout files in repo
if: ${{ steps.set-create-pr.outputs.create_pr }} == 'true'
if: ${{ env.CREATE_PR }} == 'true'
uses: actions/checkout@v4
with:
repository: 'berkeley-dsep-infra/datahub'
sparse-checkout: |
deployments/
hub/
deployments/${{ env.HUB }}
- name: install python
if: ${{ env.CREATE_PR }} == 'true'
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: install dependencies
if: ${{ env.CREATE_PR }} == 'true'
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: set git identity
if: ${{ env.CREATE_PR }} == 'true'
run: |
git config --global user.email "${{ vars.IMAGE_BUILDER_BOT_EMAIL }}"
git config --global user.name "${{ vars.IMAGE_BUILDER_BOT_NAME }}"
- name: create feature branch
if: ${{ env.CREATE_PR }} == 'true'
run: |
git checkout -b update-${{ env.HUB }}-image-tag
- name: update the image tag in hubploy.yaml for any deployments that use this image
if: ${{ env.CREATE_PR }} == 'true'
run: |
for deployment in $(grep -lr ${{ env.IMAGE }} **/hubploy.yaml); do
echo "DEPLOYMENT=${deployment}"
old_hash=$(grep ${{ env.IMAGE }} ${deployment} | awk -F":" '{print $3}')
new_hash=${IMAGE_TAG}
sed -i -e "s/${old_hash}/${new_hash}/g" ${deployment}
done
- name: add, commit and push changes
if: ${{ env.CREATE_PR }} == 'true'
run: |
CHANGED_FILES=$(git status --porcelain -uno)
git add .
git commit -m "update ${HUB} image tag to ${IMAGE_TAG}: ${CHANGED_FILES}"
git push origin update-${HUB}-image-tag
- name: see if the correct dir has been checked out, and the requirements have been installed
- name: print out a message if no PR is created
if: ${{ env.CREATE_PR }} == 'false'
run: |
ls -la
tree
echo "No PR created"

0 comments on commit b42da87

Please sign in to comment.