|
| 1 | +name: Build and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pages: write |
| 12 | + id-token: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Setup Ruby |
| 23 | + uses: ruby/setup-ruby@v1 |
| 24 | + with: |
| 25 | + ruby-version: '3.1' |
| 26 | + bundler-cache: true |
| 27 | + |
| 28 | + - name: Build site |
| 29 | + run: bundle exec jekyll build |
| 30 | + env: |
| 31 | + JEKYLL_ENV: production |
| 32 | + |
| 33 | + - name: Upload artifact for main branch |
| 34 | + if: github.ref == 'refs/heads/main' |
| 35 | + uses: actions/upload-pages-artifact@v3 |
| 36 | + with: |
| 37 | + path: ./_site |
| 38 | + |
| 39 | + # Deploy to GitHub Pages (main branch only) |
| 40 | + deploy: |
| 41 | + if: github.ref == 'refs/heads/main' |
| 42 | + environment: |
| 43 | + name: github-pages |
| 44 | + url: ${{ steps.deployment.outputs.page_url }} |
| 45 | + runs-on: ubuntu-latest |
| 46 | + needs: build |
| 47 | + steps: |
| 48 | + - name: Deploy to GitHub Pages |
| 49 | + id: deployment |
| 50 | + uses: actions/deploy-pages@v4 |
| 51 | + |
| 52 | + # PR Preview (for pull requests only) |
| 53 | + preview: |
| 54 | + if: github.event_name == 'pull_request' |
| 55 | + runs-on: ubuntu-latest |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Setup Ruby |
| 61 | + uses: ruby/setup-ruby@v1 |
| 62 | + with: |
| 63 | + ruby-version: '3.1' |
| 64 | + bundler-cache: true |
| 65 | + |
| 66 | + - name: Build PR site |
| 67 | + run: bundle exec jekyll build |
| 68 | + env: |
| 69 | + JEKYLL_ENV: production |
| 70 | + |
| 71 | + - name: Deploy PR Preview |
| 72 | + uses: peaceiris/actions-gh-pages@v3 |
| 73 | + with: |
| 74 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + publish_dir: ./_site |
| 76 | + destination_dir: pr-${{ github.event.number }} |
| 77 | + |
| 78 | + - name: Comment PR |
| 79 | + uses: actions/github-script@v7 |
| 80 | + with: |
| 81 | + script: | |
| 82 | + github.rest.issues.createComment({ |
| 83 | + issue_number: context.issue.number, |
| 84 | + owner: context.repo.owner, |
| 85 | + repo: context.repo.repo, |
| 86 | + body: '🚀 Preview deployed to: https://devnomadic.com/pr-${{ github.event.number }}/' |
| 87 | + }) |
0 commit comments