Build and Deploy #360
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# deploy fpira.com using GitHub Actions | |
name: 'Build and Deploy' | |
on: | |
push: | |
branches: | |
- main | |
- preview | |
paths-ignore: | |
- '.github/**' | |
- '_jekyll_ignore/**' | |
- README.md | |
- '.gitignore' | |
- 'repo_utils/**' | |
- '.vscode' | |
- '.vercelignore' | |
- Dockerfile | |
- .dockerignore | |
- .editorconfig | |
- '.devcontainer/**' | |
- '.html_proofer_cache/**' | |
# schedule is in UTC using cron syntax | |
schedule: | |
- cron: '45 8 * * *' | |
workflow_dispatch: | |
inputs: | |
target_ref: | |
description: "branch or ref to checkout to" | |
required: false | |
default: '' | |
jobs: | |
checks: | |
name: Checks and Deploy Info | |
runs-on: ubuntu-24.04 | |
outputs: | |
RUN_BUILD: ${{ steps.check_new_posts.outputs.RUN_BUILD }} | |
REF_NAME: ${{ steps.get_current_ref.outputs.ref }} | |
VERCEL_ARGS: ${{ steps.get_deployment_info.outputs.VERCEL_ARGS }} | |
ENV_NAME: ${{ steps.get_deployment_info.outputs.ENV_NAME }} | |
steps: | |
- name: Clone repo | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.inputs.target_ref }} | |
- name: Check for new blog posts | |
id: check_new_posts | |
uses: ./.github/actions/check-for-posts | |
- name: Get current ref (branch name or commit id) | |
id: get_current_ref | |
uses: ./.github/actions/get-current-ref | |
- name: Get deployment info | |
id: get_deployment_info | |
uses: ./.github/actions/get-deployment-info | |
with: | |
ref: ${{ steps.get_current_ref.outputs.ref }} | |
build: | |
name: Build and Deploy | |
runs-on: ubuntu-24.04 | |
environment: | |
name: ${{ needs.checks.outputs.ENV_NAME }} | |
url: ${{ steps.deploy_to_vercel.outputs.preview-url }} | |
concurrency: ${{ needs.checks.outputs.ENV_NAME }} | |
needs: [checks] | |
if: contains(needs.checks.outputs.RUN_BUILD, 'true') | |
steps: | |
- name: Clone repo | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.inputs.target_ref }} | |
fetch-tags: true | |
# Prepare environment | |
- name: Setup Jekyll environment | |
uses: ./.github/actions/setup-jekyll-env | |
- name: Write git info to site data | |
uses: ./.github/actions/git-info | |
with: | |
target_file: _data/git.json | |
# Perform CI checks | |
- name: CI checks | |
uses: ./.github/actions/ci-checks | |
if: github.ref == 'refs/heads/main' | |
# Be sure calendars have CRLF line endings | |
- name: dos2unix | |
run: | | |
sudo apt install -y dos2unix | |
unix2dos calendars/*.ics | |
# Vercel deploy | |
- name: Deploy on Vercel | |
id: deploy_to_vercel | |
uses: amondnet/[email protected] | |
with: | |
# analytics env vars are set on Vercel bc build happens there! | |
vercel-token: ${{ secrets.VERCEL_TOKEN }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
vercel-args: ${{ needs.checks.outputs.VERCEL_ARGS }} | |
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} | |
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} | |
alias-domains: | | |
fpiracom-{{BRANCH}}-pirafrank.vercel.app | |
# Algolia search index update | |
- name: Update Algolia Index | |
if: github.ref == 'refs/heads/main' | |
shell: bash | |
env: | |
JEKYLL_ENV: production | |
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} | |
run: | | |
bundle exec jekyll algolia | |
# In good and bad times, let me know how it went. | |
# This must stay at the bottom of the job. | |
- name: Send Build Push Notification | |
uses: fjogeleit/http-request-action@master | |
if: always() | |
with: | |
url: ${{ secrets.NOTIFICATION_WEBHOOK_URI }} | |
method: 'POST' | |
data: '{ "value1": "[GitHub] pirafrank/fpiracom", "value2": "Build of fpira.com (ref ${{ needs.checks.outputs.REF_NAME }}) and Algolia index update finished with status ${{job.status}}.<br>Vercel deployment: ${{ steps.deploy_to_vercel.outputs.preview-name }}<br>Vercel preview URL: ${{ steps.deploy_to_vercel.outputs.preview-url }}", "value3": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" }' | |