Skip to content

Web scraping / API re-introduction #45

Web scraping / API re-introduction

Web scraping / API re-introduction #45

name: Rebuild and publish new ubcdsci/py-intro-to-ds image on DockerHub
on:
pull_request:
types: [opened, synchronize]
paths:
- Dockerfile
jobs:
rebuild-docker:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout PR branch
uses: actions/checkout@v3
with:
fetch-depth: '0'
ref: ${{ github.head_ref }}
- name: Check if Dockerfile needs to be rebuilt
id: check-stale
run: |
echo "GitHub PR action type: ${{ github.event.action }}"
echo "Checking if the PR modifies the Dockerfile"
if [[ ${{ github.event.action }} == 'opened' ]]; then
echo "PR just opened, and it edits the Dockerfile, so rebuilding the image."
echo "stale_dockerfile=true" >> "$GITHUB_OUTPUT"
else
if git diff --quiet ${{ github.event.before }} ${{ github.event.after }} Dockerfile; then
echo "PR synchronized, but Dockerfile was not edited. Not rebuilding the image."
echo "stale_dockerfile=false" >> "$GITHUB_OUTPUT"
else
echo "PR synchronized, and Dockerfile was edited, so rebuilding the image."
echo "stale_dockerfile=true" >> "$GITHUB_OUTPUT"
fi
fi
- name: Rebuild and publish image
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
id: rebuild
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: ubcdsci/py-intro-to-ds
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
dockerfile: Dockerfile
snapshot: true
- name: Update build_html.sh script
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git pull origin ${{ github.head_ref }}
sed 's/ubcdsci\/py-intro-to-ds:[[:alnum:]]\+/ubcdsci\/py-intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' build_html.sh > build_html.tmp && mv build_html.tmp build_html.sh
chmod u+x build_html.sh
git add build_html.sh
git commit -m "update build_html.sh script with new docker image"
- name: Update build_pdf.sh script
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git pull origin ${{ github.head_ref }}
sed 's/ubcdsci\/py-intro-to-ds:[[:alnum:]]\+/ubcdsci\/py-intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' build_pdf.sh > build_pdf.tmp && mv build_pdf.tmp build_pdf.sh
chmod u+x build_pdf.sh
git add build_pdf.sh
git commit -m "update build_pdf.sh script with new docker image"
- name: Push changes to build scripts
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}