Skip to content

Enable to track the commit to generate page(s) in Actions from the corresponding PR page #353

Enable to track the commit to generate page(s) in Actions from the corresponding PR page

Enable to track the commit to generate page(s) in Actions from the corresponding PR page #353

Workflow file for this run

name: Test & Deploy
on:
push:
branches:
- main
pull_request:
branches:
- "*"
# Allows you to run this workflow manually from the Actions tab
# https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: ☑️ Checkout code
uses: actions/checkout@v4
# Need all commits to track info
with:
fetch-depth: 0
- name: 💎 Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: 🧪 Install gems
run: |
cd ./docs
bundle install
- name: 🔧 Build & Test
env:
TZ: 'Asia/Tokyo'
run: |
cd ./docs
JEKYLL_ENV=production bundle exec jekyll build
bundle exec rake upsert_data_by_readme
bundle exec rake test
# Deploy job is triggered only pushed to main branch && CI passed
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
needs: test
runs-on: ubuntu-latest
steps:
- name: ☑️ Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 💎 Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: 🧪 Install gems
run: |
cd ./docs
bundle install
- name: 📝 Extract PR number from last commit
run: |
COMMIT_MESSAGE=$(git show -s --format=%s HEAD)
PR_NUMBER=$(echo "$COMMIT_MESSAGE" | sed -nE 's/^Merge pull request #([0-9]+).*/\1/p')
if [ -n "$PR_NUMBER" ]; then
echo "PR_NUMBER=#$PR_NUMBER" >> $GITHUB_ENV; else
echo "PR_NUMBER=" >> $GITHUB_ENV
fi
- name: 🤖 Generate page(s) by README
env:
TZ: 'Asia/Tokyo'
PR_NUMBER: ${{ env.PR_NUMBER }}
run: |
cd ./docs
bundle exec rake upsert_data_by_readme
if [ -n "$(git status en ja --porcelain)" ]; then
git config --global user.name "Yohei Yasukawa"
git config --global user.email "[email protected]"
git checkout main
git add en ja
git commit -m "🤖 Generate page(s) by README $PR_NUMBER"
git push origin main
fi
- name: 🔧 Build all pages
env:
TZ: 'Asia/Tokyo'
run: |
cd ./docs
JEKYLL_ENV=production bundle exec jekyll build
- name: 🚀 Deploy to gh-pages branch
if: github.ref == 'refs/heads/main' && job.status == 'success'
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_site