Skip to content

Commit

Permalink
Merge branch 'htw-imi-showtime:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gerritbehrens committed Jul 13, 2024
2 parents e27bd2a + c6d9075 commit dc77f04
Show file tree
Hide file tree
Showing 53 changed files with 485 additions and 142 deletions.
26 changes: 22 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

### Opening a Pull Request to Update your Project

I've started a documentation on how we should use the forking workflow here:

[https://github.com/htw-imi-showtime/showtime-website/blob/documentation/doc/forking-workflow/index.md](https://github.com/htw-imi-showtime/showtime-website/blob/documentation/doc/forking-workflow/index.md)
(will not be merged to main due to file sizes)

Please follow these Steps & Guidelines for your Pull Request:

#### Before you Request a Review Check and Tick these Boxes:
Expand All @@ -11,7 +16,7 @@ Please follow these Steps & Guidelines for your Pull Request:
[] make sure that your PR contains only files / file changes within your project subdirectory.
[] make sure that all your file names consist only of lower case letters, numbers, or [-_.] - with only one . for the file extension
[] delete all unnecessary files from your PR (including cat.jpg and kitty.jpg)
[] check the image file sizes. All Images have to be as small as possible. See [./doc/disk_usage.md](./doc/disk_usage.md) about this issues, there's a script: [./bin/images-smaller.sh](./bin/images-smaller.sh)
[] check the image file sizes. All Images have to be as small as possible. See [./doc/disk_usage.md](https://github.com/htw-imi-showtime/showtime-website/blob/main/doc/disk_usage.md) about this issues, there's a script: [./bin/images-smaller.sh](https://github.com/htw-imi-showtime/showtime-website/blob/main/bin/images-smaller.sh)

**Note that if you fail to do so, I may simply reduce the file sizes brute force using
the script above - WITHOUT CHECKING THE QUALITY**
Expand All @@ -32,14 +37,27 @@ the script above - WITHOUT CHECKING THE QUALITY**
4. If your disk usage exceeds 500K, provide a reason while you want to include so many images or why certain images need to be that big:


#### IMPORTANT: if you run into trouble / If the checks fail...

#### All good? Request a Review!
- if you cannot figure out why a check fails or you think that it may be wrong,
don't hesitate to contact me! (e.g. by requesting a review and commenting in the pr)

[] if everythings seems fine, request a review by bkleinen on github. (on the upper right)
- run the checks locally with:

./bin/check-project-update-pr/run-all.sh <project_id>

#### All good?

If all checks run successfully the PR will be reviewed and, if no
further changes are requested, merged and closed.
(this is the time to update and start a new branch!)

### More Information

We are using the Forking Workflow.

- [Best Practices for Pull Requests](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/getting-started/best-practices-for-pull-requests)
- Atlassian Git Tutorial: [Forking Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow)
- GitHub Docs: [Collaborating with pull requests](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests)
- Documentation in [README.MD](https://github.com/htw-imi-showtime/showtime-website/blob/main/README.MD) and [/doc](https://github.com/htw-imi-showtime/showtime-website/blob/main/doc)

- Documentation in README.MD and /doc
45 changes: 45 additions & 0 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build Hugo and Check Title

on:
pull_request:
workflow_dispatch:

jobs:
hugo-build:
if: github.repository == 'htw-imi-showtime/showtime-website'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
- name: Get Theme
run: |
git submodule update --init themes/showtime-theme-2021
- name: Hugo setup
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.128.0'
extended: true

- name: Build
run: |
hugo \
--environment staging \
--baseURL "https://htw-imi-showtime.github.io/tryout/" \
--buildDrafts
check-title:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 1
- name: check pr title starts with project id or "STW"
id: extract_pid
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
./bin/check-project-update-pr/check-title.sh "$PR_TITLE"
64 changes: 33 additions & 31 deletions .github/workflows/check-project-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,12 @@ name: Check Project Update PR

on:
pull_request:
paths:
- 'content/ss24/**'
workflow_dispatch:

jobs:
hugo-build:
if: github.repository == 'htw-imi-showtime/showtime-website'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
- name: Get Theme
run: |
git submodule update --init themes/showtime-theme-2021
- name: Hugo setup
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.128.0'
extended: true

- name: Build
run: |
hugo \
--environment staging \
--baseURL "https://htw-imi-showtime.github.io/tryout/" \
--buildDrafts

check-title:
runs-on: ubuntu-latest
steps:
Expand All @@ -42,9 +21,9 @@ jobs:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
./bin/check-project-update-pr/check-title.sh "$PR_TITLE"
check_disk_usage:
if: ${{ ! startsWith(github.event.pull_request.title, 'STW') }}
needs: check-title
runs-on: ubuntu-latest
# Required permissions
Expand All @@ -65,6 +44,7 @@ jobs:
get_files_in_pr:
if: ${{ ! startsWith(github.event.pull_request.title, 'STW') }}
name: "Download changed files list"
needs: check-title
runs-on: ubuntu-latest
Expand Down Expand Up @@ -98,27 +78,45 @@ jobs:
- 'content/**/${{ steps.extract_pid.outputs.project_id }}-*/**'
other_files:
- '!content/**/${{ steps.extract_pid.outputs.project_id }}-*/**'
with_spaces:
- '**/*\ *'
- name: create artifact dir and empty files
run: |
mkdir changed_files
touch changed_files/files-project.txt
touch changed_files/files-other.txt
touch changed_files/files-with-spaces.txt
- name: 'fail if pr contains files with spaces'
if: (steps.filter.outputs.with_spaces == 'true')
env:
all_files: ${{ steps.filter.outputs.with_spaces_files }}
run: |
echo "--------- PR contains files with spaces in their name - EXITING."
echo $all_files | tr ' ' '\n'
exit 101
- name: write changed files
if: (steps.filter.outputs.in_project == 'true')
env:
all_files: ${{ steps.filter.outputs.in_project_files }}
run: |
echo "--------- project_files:"
echo ${{ steps.filter.outputs.in_project_files }} | tr ' ' '\n'
echo ${{ steps.filter.outputs.in_project_files }} > changed_files/files-project.txt
pr_adds_files=$(bin/check-project-update-pr/remove_deleted_files.sh $all_files)
echo $pr_adds_files | tr ' ' '\n'
echo $pr_adds_files > changed_files/files-project.txt
- name: 'files outside of project folder'
if: (steps.filter.outputs.other_files == 'true')
env:
all_files: ${{ steps.filter.outputs.other_files_files }}
run: |
echo "--------- non_project_files (may not be part of project update PR!):"
echo ${{ steps.filter.outputs.other_files_files }} | tr ' ' '\n'
echo ${{ steps.filter.outputs.other_files_files }} > changed_files/files-other.txt
pr_adds_files=$(bin/check-project-update-pr/remove_deleted_files.sh $all_files)
echo $pr_adds_files | tr ' ' '\n'
echo $pr_adds_files > changed_files/files-other.txt
- name: list artifact files
run: |
Expand All @@ -137,6 +135,7 @@ jobs:


check_artifact:
if: ${{ ! startsWith(github.event.pull_request.title, 'STW') }}
name: "look for artifact files"
needs: get_files_in_pr
runs-on: ubuntu-latest
Expand All @@ -158,6 +157,7 @@ jobs:
check_files_in_pr:
if: ${{ ! startsWith(github.event.pull_request.title, 'STW') }}
name: "check for files outside of project folder"
needs: get_files_in_pr
runs-on: ubuntu-latest
Expand All @@ -181,6 +181,7 @@ jobs:


check_for_cats_download:
if: ${{ ! startsWith(github.event.pull_request.title, 'STW') }}
name: "check for cat template files"
needs: get_files_in_pr
runs-on: ubuntu-latest
Expand All @@ -203,6 +204,7 @@ jobs:
check_file_name_convention:
if: ${{ ! startsWith(github.event.pull_request.title, 'STW') }}
name: "check file name conventions"
needs: get_files_in_pr
runs-on: ubuntu-latest
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/deploy_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: PR Hugo Deploy
# see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
on:
pull_request:
# types: [labeled]
workflow_dispatch:

jobs:
build:
if: ${{ contains( github.event.pull_request.labels.*.name, 'deploy_pr') }}
# if: ${{ (github.event.label.name == 'deploy_pr') && (github.repository == 'htw-imi-showtime/showtime-website') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
- name: Get Theme
run: |
git submodule update --init themes/showtime-theme-2021
- name: Hugo setup
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.128.0'
extended: true

- name: Update Config
run: |
ls config/pull_request
cat config/pull_request/config.toml
sed -i "s/101/${{ github.event.number }}/g" config/pull_request/config.toml
echo "----- updated config: "
cat config/pull_request/config.toml
- name: Build
run: |
hugo \
--environment pull_request \
--baseURL "https://htw-imi-showtime.github.io/pull_request/${{ github.event.number }}/" \
--buildDrafts \
--destination hugo_generated_site/public
- name: "Upload artifact"
uses: actions/upload-artifact@v4
with:
name: hugo_site
path: hugo_generated_site

# see https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: "pr number"
run: |
echo ${{ github.event.number }}
- name: Download a single artifact
uses: actions/download-artifact@v4
with:
name: hugo_site
path: hugo_generated_site

- name: Push to pull_request repo
uses: cpina/github-action-push-to-another-repository@main
env:
SSH_DEPLOY_KEY: ${{ secrets.PULL_REQUEST_DEPLOY_KEY }}
with:
source-directory: 'hugo_generated_site/public'
destination-github-username: 'htw-imi-showtime'
destination-repository-name: 'pull_request'
user-email: [email protected]
target-branch: gh-pages
target-directory: ${{ github.event.number }}
- name: show url
run: |
echo "after the pages build and deployment action https://github.com/htw-imi-showtime/pull_request/actions"
echo "available at https://htw-imi-showtime.github.io/pull_request/${{ github.event.number }}"
# https://cpina.github.io/push-to-another-repository-docs/
# https://github.com/htw-imi-showtime/pull_request
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ node_modules/
.linkinator/
hugo-temp/
tmp/
files-other.txt
files-project.txt
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hugo : open
#- hugo --baseURL http://localhost:1313/pathprefix --navigateToChanged --port=1313 server
# - hugo --baseURL http://localhost:1313/pathprefix --navigateToChanged --buildDrafts -p 1313 server
- hugo --baseURL http://localhost:1313/pathprefix --navigateToChanged --buildDrafts --environment pull_request -p 1313 server
- hugo --baseURL http://localhost:1313/pathprefix --navigateToChanged --buildDrafts --environment development -p 1313 server

hugoP : open
- hugo -p 1313 server
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,19 @@ git push

Once your branch was merged, you may preview your project's page on our staging server: https://htw-imi-showtime.github.io/

### We are using the Forking Workflow.

Note: we are essentially using the "Forking Workflow" as described in the Atlassian Documentation here:
[https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow)

I've started a documentation on how we should use the forking workflow here:

[https://github.com/htw-imi-showtime/showtime-website/blob/documentation/doc/forking-workflow/index.md](https://github.com/htw-imi-showtime/showtime-website/blob/documentation/doc/forking-workflow/index.md)
(will not be merged to main due to file sizes)


## Deploy your Fork on GH-Pages

** funktioniert wieder! **

You can easily deploy your fork on GH-Pages by following the instructions here:
[http://about-hugo.github.io/hugo/quick/](http://about-hugo.github.io/hugo/quick/)
Expand Down
21 changes: 21 additions & 0 deletions bin/check-project-update-pr/changed-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# the gh action will access the gh api to ask for changed files
# note that this only works if your main is up-to-date with origin/main
shopt -s nocaseglob

diff_main=$(git diff --name-only main)
files_in_pr=""
for f in $diff_main; do
# echo $f
dir_name=$(dirname $f)
base_name=$(basename $f)
found_file=$(find $dir_name -maxdepth 1 -name $base_name)
# echo "found file: ##$found_file##"
if test -n "$found_file"
then
files_in_pr="$files_in_pr $f"
fi
done

echo $files_in_pr | tr ' ' '\n'
Loading

0 comments on commit dc77f04

Please sign in to comment.