Skip to content

Commit

Permalink
Gh pages deploy fix (#336), fixes #325, add check for changed files i…
Browse files Browse the repository at this point in the history
…n pr

* add gitinfo page, use env variables in gh branch wf

* add workflow to check files changed in pr
  • Loading branch information
bkleinen authored Jun 30, 2024
1 parent c22774f commit 90d5b56
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 13 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/archive/context.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Context testing
on:
workflow_dispatch:

jobs:
dump_contexts_to_log:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: pr title
env:
TITLE: ${{ github.event.pull_request.title }}
P_ID: "${TITLE:0:2}"

run: |
echo P_ID: "$P_ID"
echo "Title: $TITLE"
PID="${TITLE:0:2}"
echo "new pid $PID"
which tr
PID2=$(echo $PID | tr '[:upper:]' '[:lower:]')
echo "new pid2 $PID2"
# - name: Dump job context
# env:
# JOB_CONTEXT: ${{ toJson(job) }}
# run: echo "$JOB_CONTEXT"
# - name: Dump steps context
# env:
# STEPS_CONTEXT: ${{ toJson(steps) }}
# run: echo "$STEPS_CONTEXT"
# - name: Dump runner context
# env:
# RUNNER_CONTEXT: ${{ toJson(runner) }}
# run: echo "$RUNNER_CONTEXT"
# - name: Dump strategy context
# env:
# STRATEGY_CONTEXT: ${{ toJson(strategy) }}
# run: echo "$STRATEGY_CONTEXT"
# - name: Dump matrix context
# env:
# MATRIX_CONTEXT: ${{ toJson(matrix) }}
# run: echo "$MATRIX_CONTEXT"

61 changes: 61 additions & 0 deletions .github/workflows/archive/only-change-own-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: check only own files have been changed

on:
workflow_dispatch:

jobs:
check-own-folder:
runs-on: ubuntu-latest
steps:
- name: vars
run: |
echo "some github variables:" \
echo $GITHUB_REF \
echo "sha: ${{ github.event.head_commit.sha }}" \
echo "message: ${{ github.event.head_commit.message }}" \
echo "pr commit sha: ${{ github.event.pull_request.head.sha }}" \
echo "pr commit ref: ${{ github.event.pull_request.head.ref }}" \
echo "pr commit message: ${{ github.event.pull_request.head.message }}" \
echo "pr commit: ${{ github.event.pull_request.head }}" \
echo "base ref: ${{ github.event.pull_request.base.ref }}" \
echo "base sha: ${{ github.event.pull_request.base.sha }}"
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: false

- name: "diff commit"
run: |
git status
echo "files changed: "
git diff --name-only ${{ github.event.head_commit.sha }}
continue-on-error: true

- name: "diff pr"
continue-on-error: true
run: |
echo "files changed: "
git diff --name-only ${{ github.event.pull_request.head.sha }}
- name: "diff base head"
continue-on-error: true
run: |
echo "files changed: "
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
- name: "git base head grep"
continue-on-error: true
run: |
git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -v ss24
- name: "git diff main with check"
continue-on-error: true
run: |
if [[ "" != $(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -v ss24) ]]; then
echo "more files changed than allowed:"
git diff --name-only main | grep -v ss24
else
echo "all good"
fi
30 changes: 30 additions & 0 deletions .github/workflows/archive/test-checkout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: test checkout action
on:
# push:
# branches:
# - gh_pages_deploy_fix # Set a branch that will trigger a deployment
workflow_dispatch:

jobs:
checkout-only:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 1 # Fetch all history for .GitInfo and .Lastmod

- name: Get Theme
run: |
git submodule update --init themes/showtime-theme-2021
- name: Echo something
run: echo "Output after checkout - should work"

job-after-checkout:
runs-on: ubuntu-latest
needs: checkout-only
steps:
- name: Echo something
run: echo "Output from after-checkout job"
6 changes: 3 additions & 3 deletions .github/workflows/build_pr.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: pull request
name: PR Hugo Page

on:
pull_request:

workflow_dispatch:

jobs:
deploy:
build:
if: github.repository == 'htw-imi-showtime/showtime-website'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: false
- name: Get Theme
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
name: gh-pages in fork
# Generic Workflow that builds the hugo page from . (root dir of the repo)
# and publishes the page with the new actions/deploy-pages gh action.
# sets the baseURL for hugo to 'https://<owner>.github.io/<repo>'

# use it with <repo>->Settings->Pages Source "GitHub Actions"
# Contains a RUN_IF to prevent it from running in the original repo

name: Deploy Page using GH-Actions

on:
push:
branches:
- main # Set a branch that will trigger a deployment
workflow_dispatch:

permissions:
contents: read
pages: write
Expand All @@ -17,18 +24,18 @@ concurrency:
group: "pages"
cancel-in-progress: false

jobs:
jobs:
build:
name: Hugo Page Build
if: github.repository_owner != 'htw-imi-showtime'
# if: ${{ github.repository_owner != 'htw-imi-showtime' }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 1
fetch-depth: 1 # Fetch all history for .GitInfo and .Lastmod

- name: Get Theme
run: |
Expand All @@ -46,19 +53,19 @@ jobs:
--environment production \
--buildDrafts \
--baseURL 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}'
- name: "Upload artifact"
uses: actions/upload-pages-artifact@v3
with:
path: public

deploy:
name: Deploy to GH Pages
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/gh-pages-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generic Workflow that builds the hugo page from . (root dir of the repo)
# sets the baseURL for hugo to 'https://<owner>.github.io/<repo>'
# publishes the hugo page using the (older) option by pushing the
# page to the branch gh-pages

# use it with <repo>->Settings->Pages "Deploy from a branch"
# Select Branch: "gh-pages" Select Folder: "/(root)"
# Contains a RUN_IF to prevent it from running in the original repo

# This is here for legacy reasons. If in doubt, use the workflow in gh-pages-action.yml !

name: Deploy Page using Branch

on:
push:
branches:
- gh_pages_deploy_fix # Set a branch that will trigger a deployment
workflow_dispatch:

jobs:

deploy:
if: ${{ github.repository_owner != 'htw-imi-showtime' }}
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: false
fetch-depth: 1 # Fetch all history for .GitInfo and .Lastmod

- name: Get Theme
run: |
git submodule update --init themes/showtime-theme-2021
# see https://github.com/marketplace/actions/hugo-setup
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: 'latest'
extended: true

- name: Build
run: |
hugo \
--environment production \
--buildDrafts \
--baseURL 'https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}'
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
if: github.ref == 'refs/heads/main'
with:
publish_dir: ./public
2 changes: 1 addition & 1 deletion .github/workflows/hugo-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
hugo-version: [0.115.1, 0.127.0, 0.128.0]
hugo-version: [0.128.0]
hugo-environment: [staging, production]
steps:
- uses: actions/checkout@v4
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/only-change-own-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Own Files Only

# this workflow checks whether a pull request changes only files in the project folder"
# PR Titles have to start with the Project ID! (e.g. B1: ....)
on:
pull_request:


workflow_dispatch:

jobs:
check-own-files:
runs-on: ubuntu-latest
steps:
- name: vars
run: |
echo "some github variables:" \
echo $GITHUB_REF \
echo "sha: ${{ github.event.head_commit.sha }}" \
echo "message: ${{ github.event.head_commit.message }}" \
echo "pr commit sha: ${{ github.event.pull_request.head.sha }}" \
echo "pr commit ref: ${{ github.event.pull_request.head.ref }}" \
echo "pr commit message: ${{ github.event.pull_request.head.message }}" \
echo "pr commit: ${{ github.event.pull_request.head }}" \
echo "base ref: ${{ github.event.pull_request.base.ref }}" \
echo "base sha: ${{ github.event.pull_request.base.sha }}" \
echo "event: ${{ github.event }}" \
echo "event: ${{ github.event.message }}" \
- uses: actions/checkout@v4
with:
submodules: false

- name: "checkout relevant refs"
run: |
git log
git status
git fetch --no-tags --depth=1 origin main
git checkout main
echo "about to pr base"
git fetch origin ${{ github.event.pull_request.base.sha }}
git checkout -b pr_base ${{ github.event.pull_request.base.sha }}
# echo "about to checkout merge commit"
# git fetch origin ${{ github.event.pull_request.merge_commit_sha }}
# git checkout -b pr_merge_commit ${{ github.event.pull_request.merge_commit_sha }}
echo "about to checkout head"
git fetch origin ${{ github.event.pull_request.head.sha }}
git checkout -b pr_head ${{ github.event.pull_request.head.sha }}
- name: extract project id
id: extract_pid
env:
PR_TITLE: ${{ github.event.pull_request.title }}

run: |
echo P_ID: "$P_ID"
echo "PR_TITLE: $PR_TITLE"
PID="${PR_TITLE:0:2}"
echo "PID $PID"
PID2=$(echo $PID | tr '[:upper:]' '[:lower:]')
echo "PID2 $PID2"
echo "project_id=$PID2" >> $GITHUB_OUTPUT
echo "allowed_path=ss24/$PID2" >> $GITHUB_OUTPUT
- name: "diff base head"
continue-on-error: true
run: |
echo "files changed: "
git diff --name-only pr_base pr_head
- name: "grep test"
continue-on-error: true
run: |
echo "files changed: "
git diff --name-only pr_base pr_head | grep -v ${{ steps.extract_pid.outputs.allowed_path }}
- name: "git diff main with check"
run: |
if [[ "" != $(git diff --name-only pr_base pr_head | grep -v ${{ steps.extract_pid.outputs.allowed_path }}) ]]; then
echo "ERROR: More files changed than allowed!"
echo "------ Additional Files: "
git diff --name-only pr_base pr_head | grep -v "${{ steps.extract_pid.outputs.allowed_path }}"
echo "------ Allowed Files:"
git diff --name-only pr_base pr_head | grep "${{ steps.extract_pid.outputs.allowed_path }}"
exit 123
else
echo "all good"
fi
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,7 @@ ci:
- open https://htw-imi-showtime.github.io/tryout/

get-theme:
- git submodule update --init themes/showtime-theme-2021
- git submodule update --init themes/showtime-theme-2021

quick-push:
- git commit -am "commit at $(shell date "+%H:%M:%S")" && git push && open https://github.com/htw-imi-showtime/showtime-website/actions
Loading

0 comments on commit 90d5b56

Please sign in to comment.