Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve workflows #169

Merged
merged 11 commits into from
Jan 22, 2025
65 changes: 65 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.115.4
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Dart Sass
run: sudo snap install dart-sass
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup Pages
id: pages
uses: actions/configure-pages@v4
- name: Install Node.js dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
- name: Build with Hugo
env:
HUGO_ENVIRONMENT: production
HUGO_ENV: production
run: hugo --gc --minify

- name: Archive Hugo Build Output
run: zip -r hugo-site.zip public/

- name: Set current datetime as output
id: set_datetime
env:
TZ: "Asia/Tokyo"
run: echo "CURRENT_DATETIME=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "release-${{ github.sha }}-${{ github.run_id }}"
release_name: "${{ steps.set_datetime.outputs.CURRENT_DATETIME }}"
draft: false
prerelease: false

- name: Upload Release Assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./hugo-site.zip
asset_name: hugo-site.zip
asset_content_type: application/zip
32 changes: 32 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy

on:
workflow_dispatch:
workflow_run:
workflows:
- Build
types:
- completed

jobs:
deploy:
runs-on: self-hosted
steps:
- name: Create Temporary Directory
id: create_temp_dir
run: |
TEMP_DIR=$(mktemp -d)
echo "TEMP_DIR=$TEMP_DIR" >> $GITHUB_OUTPUT

- name: Download the Release Asset
run: |
url=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | grep "browser_download_url.*hugo-site.zip" | cut -d '"' -f 4)
curl -L -o "${{ steps.create_temp_dir.outputs.TEMP_DIR }}/hugo-site.zip" "$url"

- name: Unzip the Release Asset
run: |
unzip "${{ steps.create_temp_dir.outputs.TEMP_DIR }}/hugo-site.zip" -d "${{ steps.create_temp_dir.outputs.TEMP_DIR }}/unzipped"
rm -rf ../../../../public
mkdir -p ../../../../public
mv "${{ steps.create_temp_dir.outputs.TEMP_DIR }}/unzipped/public/"* ../../../../public/
rm -rf "${{ steps.create_temp_dir.outputs.TEMP_DIR }}"
88 changes: 44 additions & 44 deletions .github/workflows/disk_space_alert.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
name: Disk Space Alert
on:
workflow_dispatch:
schedule:
- cron: '0 18 * * 1'
workflow_run:
workflows:
- Build Hugo site and upload to release
types:
- completed
jobs:
check-disk:
runs-on: self-hosted
steps:
- name: Check Disk Usage
id: check_disk
run: |
DISK_USAGE=$(du -sm ~ | awk '{printf "%.1f", $1 / 1024}')
TOTAL_DISK=4
echo "DISK_USAGE=${DISK_USAGE}" >> $GITHUB_OUTPUT
echo "TOTAL_DISK=${TOTAL_DISK}" >> $GITHUB_OUTPUT
echo "## 📝 ディスク使用状況レポート" >> $GITHUB_STEP_SUMMARY
echo "現在のディスクの使用量は ${DISK_USAGE} GB / ${TOTAL_DISK} GB です。" >> $GITHUB_STEP_SUMMARY
- name: Check Threshold
run: |
THRESHOLD=3
DISK_USAGE=${{ steps.check_disk.outputs.DISK_USAGE }}
TOTAL_DISK=${{ steps.check_disk.outputs.TOTAL_DISK }}
if (( $(echo "$DISK_USAGE > $THRESHOLD" | bc -l) )); then
echo "## ⚠️ 警告: 対応が必要" >> $GITHUB_STEP_SUMMARY
echo "ディスク使用量が上限に近づいています。" >> $GITHUB_STEP_SUMMARY
echo "不要なファイルを削除してください。" >> $GITHUB_STEP_SUMMARY
echo "必要な場合には、情報基盤センターにディスク容量の増量を依頼してください。" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "## ✅ 正常: 対応は不要" >> $GITHUB_STEP_SUMMARY
echo "ディスク使用量は正常です。" >> $GITHUB_STEP_SUMMARY
fi
name: Disk Space Alert

on:
workflow_dispatch:
schedule:
- cron: "* * * * */7"
workflow_run:
workflows:
- Deploy
types:
- completed

jobs:
check-disk:
runs-on: self-hosted
steps:
- name: Check Disk Usage
id: check_disk
run: |
DISK_USAGE=$(du -sm ~ | awk '{printf "%.2f", $1 / 1024}')
TOTAL_DISK=4

echo "DISK_USAGE=${DISK_USAGE}" >> $GITHUB_OUTPUT
echo "TOTAL_DISK=${TOTAL_DISK}" >> $GITHUB_OUTPUT

echo "## 📝 ディスク使用状況レポート" >> $GITHUB_STEP_SUMMARY
echo "現在のディスクの使用量は ${DISK_USAGE} GB / ${TOTAL_DISK} GB です。" >> $GITHUB_STEP_SUMMARY

- name: Check Threshold
run: |
THRESHOLD=3
DISK_USAGE=${{ steps.check_disk.outputs.DISK_USAGE }}
TOTAL_DISK=${{ steps.check_disk.outputs.TOTAL_DISK }}

if (( $(echo "$DISK_USAGE > $THRESHOLD" | bc -l) )); then
echo "## ⚠️ 警告: 対応が必要" >> $GITHUB_STEP_SUMMARY
echo "ディスク使用量が上限に近づいています。" >> $GITHUB_STEP_SUMMARY
echo "不要なファイルを削除してください。" >> $GITHUB_STEP_SUMMARY
echo "必要な場合には、情報基盤センターにディスク容量の増量を依頼してください。" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "## ✅ 正常: 対応は不要" >> $GITHUB_STEP_SUMMARY
echo "ディスク使用量は正常です。" >> $GITHUB_STEP_SUMMARY
fi
106 changes: 0 additions & 106 deletions .github/workflows/hugo.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# nitmic-hp

![workflow](https://github.com/nitmic/nitmic-website/actions/workflows/hugo.yml/badge.svg)
![workflow](https://github.com/nitmic/nitmic-website/actions/workflows/build.yml/badge.svg)
![workflow](https://github.com/nitmic/nitmic-website/actions/workflows/deploy.yml/badge.svg)
![workflow](https://github.com/nitmic/nitmic-website/actions/workflows/disk_space_alert.yml/badge.svg)

URL:http://nitmic.club.nitech.ac.jp/

Expand Down