dandk105 / webapp_study

web app の作成を通して、gitの使い方や、ユニットテストについてQAの人が勉強するためのリポジトリです
https://dandk105.github.io/webapp_study/
MIT License
0 stars 0 forks source link

github pagesのactionsをメインブランチにプッシュしたときではなく、プルリクを作ったときにビルドする #59

Closed dandk105 closed 10 months ago

dandk105 commented 10 months ago

今はプルリクをプッシュしたときにビルドとデプロイを実行するようにしているが、これをプルリクを作成したときにビルドするようにする

dandk105 commented 10 months ago
name: Deploy Jekyll with GitHub Pages dependencies preinstalled

on:
  # Runs on pushes targeting the default branch
ここをpushではなく、pull requestsにする
 push:
    branches: ["main"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  # Build job
  build:
    runs-on: ubuntu-latest
   # ここのデフォルト必要ないかも
    defaults:
      run:
        working-directory: ./pages
    steps:
 #ここの pathを ${{ github.workspace }}/pages で指定してあげるコトデめんどくさい設定が解決するのでは?
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          # Jekyll build のアクションで使われているRubyのバージョンは2.8 とかで
          # 利用しているテーマのバージョンがそれ以上なのでテーマのビルドがされないため、それを回避するために3.1を指定している
          ruby-version: '3.1'
          bundler-cache: true
      - name: Setup Pages
        id: setup-pages
        uses: actions/configure-pages@v4
      - name: Install dependencies
        # Jekyll を実行する為に、bundle install をして依存関係を全てインストールする
        run: bundle install
      - name: Build with Jekyll
        run: bundle exec jekyll build --baseurl "${{ steps.setup-pages.outputs.base_path }}"
        env:
          JEKYLL_ENV: production
      - name: Fix dir permissions
        run: |
          chmod -c -R +rX "_site/" | while read line; do
            echo "::warning title=Invalid file permissions automatically fixed::$line"
          done
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v2
        with:
# ここのpathを変える必要がありそう
          path: ${{ github.workspace }}/pages/_site
dandk105 commented 10 months ago
on:
  push:
    branches:
      - main
    paths:
      - 'docs/**'

paths をpages/指定してあげることでpagesディレクトリに変更があった時のみに動かす様にactionを限定できる