Skip to content

Commit

Permalink
Merge pull request #576 from UBC-DSCI/main
Browse files Browse the repository at this point in the history
Update to sync with Python 1st ed
  • Loading branch information
trevorcampbell authored Dec 23, 2023
2 parents 7a53425 + db6e782 commit cdf7d33
Show file tree
Hide file tree
Showing 131 changed files with 73,442 additions and 3,997 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'source/*.css'
- 'data/**'
- 'img/**'
- 'build_html.sh'

jobs:
deploy-book:
Expand All @@ -36,6 +37,6 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/
force_orphan: true
force_orphan: true # this will clean up all previous PR previews / main branch preview
cname: datasciencebook.ca

45 changes: 45 additions & 0 deletions .github/workflows/deploy_main_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Rebuild and deploy dev version of book to gh-pages branch in dev/ folder
on:
push:
branches:
- main
paths:
- 'index.Rmd'
- '_bookdown.yml'
- '_output.yml'
- 'source/*.Rmd'
- 'source/*.bib'
- 'source/*.css'
- 'data/**'
- 'img/**'
- 'build_html.sh'

jobs:
deploy-main-preview:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- name: checkout
uses: actions/checkout@v2
with:
ref: 'main'

- name: Build the book
run: |
./build_html.sh
# Push the book's HTML to github-pages
- name: GitHub Pages action
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/
keep_files: true
destination_dir: dev
# force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews



62 changes: 62 additions & 0 deletions .github/workflows/deploy_pr_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Rebuild and deploy PR version of book to gh-pages branch in pull###/ folder"
on:
pull_request:
types: [opened, synchronize]
paths:
- 'index.Rmd'
- '_bookdown.yml'
- '_output.yml'
- 'source/*.Rmd'
- 'source/*.bib'
- 'source/*.css'
- 'data/**'
- 'img/**'
- 'Dockerfile'
branches:
- 'main'

jobs:
deploy-pr-preview:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
pull-requests: write

steps:
- name: Wait for potential build environment update
uses: fountainhead/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
checkName: "Rebuild docker image"
ref: ${{ github.event.pull_request.head.sha }}
timeoutSeconds: 60000

- name: Checkout the repo
uses: actions/checkout@v2
with:
fetch-depth: '0'
ref: ${{ github.head_ref }}

- name: Build the book
run: |
./build_html.sh
# Push the book's HTML to github-pages
- name: GitHub Pages action
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/
keep_files: true
destination_dir: pull${{ github.event.number }}
# force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews

- name: Post URLS to PR thread
uses: mshick/[email protected]
with:
message: |
Hello! I've built a preview of your PR so that you can compare it to the current `main` branch.
* PR deploy preview available [here](https://datasciencebook.ca/pull${{ github.event.number }}/index.html)
* Current `main` deploy preview available [here](https://datasciencebook.ca/dev/index.html)
* Public production build available [here](https://datasciencebook.ca)
48 changes: 37 additions & 11 deletions .github/workflows/update_build_environment.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
name: Rebuild and publish new ubcdsci/intro-to-ds image on DockerHub
on:
push:
branches:
- main
paths:
- Dockerfile
pull_request:
types: [opened, synchronize]
jobs:
rebuild-docker:
name: Rebuild docker image
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout main
- name: Checkout PR branch
uses: actions/checkout@v3
with:
fetch-depth: '0'
ref: 'main'
ref: ${{ github.head_ref }}
- name: Check if Dockerfile needs to be rebuilt
id: check-stale
run: |
echo "Checking if Dockerfile was modified since last commit on this PR"
echo "GitHub PR action type: ${{ github.event.action }}"
if [ "${{ github.event.action }}" == "opened" ]; then
echo "GitHub base ref: ${{ github.event.pull_request.base.sha }}"
echo "GitHub head ref: ${{ github.event.pull_request.head.sha }}"
BEFORE=${{ github.event.pull_request.base.sha }}
AFTER=${{ github.event.pull_request.head.sha }}
else
echo "GitHub event before: ${{ github.event.before }}"
echo "GitHub event after: ${{ github.event.after }}"
BEFORE=${{ github.event.before }}
AFTER=${{ github.event.after }}
fi
if git diff --quiet $BEFORE $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
- name: Rebuild and publish image
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
id: rebuild
uses: elgohr/Publish-Docker-Github-Action@v5
with:
Expand All @@ -26,33 +48,37 @@ jobs:
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 main
git pull origin ${{ github.head_ref }}
sed 's/ubcdsci\/intro-to-ds:[[:alnum:]]\+/ubcdsci\/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 main
git pull origin ${{ github.head_ref }}
sed 's/ubcdsci\/intro-to-ds:[[:alnum:]]\+/ubcdsci\/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: Update docker-compose.yml 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 main
git pull origin ${{ github.head_ref }}
sed 's/ubcdsci\/intro-to-ds:[[:alnum:]]\+/ubcdsci\/intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' docker-compose.yml > docker-compose.tmp && mv docker-compose.tmp docker-compose.yml
git add docker-compose.yml
git commit -m "update docker-compose.yml 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: 'main'
branch: ${{ github.head_ref }}
Loading

0 comments on commit cdf7d33

Please sign in to comment.