[ci] build and deploy the site #42
This file contains hidden or 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
| # Build Resume and Deploy to Firebase Hosting | |
| name: Generate Resume and Deploy | |
| 'on': | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| # First job to build the resume and push it to the repository | |
| build_resume: | |
| # Only run this job if the commit message contains [resume] | |
| if: contains(github.event.head_commit.message, '[resume]') | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step to checkout the repository | |
| - name: Checkout Repo for Resume | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # Step to compile the LaTeX resume | |
| - name: Compile Resume LaTeX to PDF | |
| uses: xu-cheng/latex-action@v2 | |
| with: | |
| # The root LaTeX file to be compiled | |
| root_file: main.tex | |
| # The working directory for this action | |
| working_directory: resume_builder | |
| # Extra arguments to be passed to the LaTeX engine | |
| args: -pdf -file-line-error -halt-on-error -interaction=nonstopmode | |
| # Arbitrary bash codes to be executed before compiling LaTeX documents | |
| pre_compile: tlmgr update --self && tlmgr update --all | |
| # Arbitrary bash codes to be executed after compiling LaTeX documents | |
| post_compile: latexmk -c | |
| latexmk_use_xelatex: true | |
| # Move the pdf to the public folder | |
| - name: Move Resume.pdf file | |
| run: | | |
| mv ./resume_builder/main.pdf ./public/resume.pdf | |
| # Retrieve the sha of the file in the repository if it exists | |
| - name: Get SHA of Resume.pdf file | |
| id: get-sha | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const pdf = fs.readFileSync(path.resolve('./public/resume.pdf')); | |
| const pdfBase64 = Buffer.from(pdf).toString('base64'); | |
| const { data } = await github.rest.repos.getContent({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| path: 'public/resume.pdf' | |
| }); | |
| const sha = data.sha; | |
| core.setOutput('sha', sha); | |
| # Step to push the PDF file to the repository using the SHA | |
| - name: Upload Resume.pdf file to repository | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| const pdf = fs.readFileSync(path.resolve('./public/resume.pdf')); | |
| const pdfBase64 = Buffer.from(pdf).toString('base64'); | |
| const sha = '${{ steps.get-sha.outputs.sha }}'; | |
| const { data } = await github.rest.repos.createOrUpdateFileContents({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| path: 'public/resume.pdf', | |
| message: 'Update Resume.pdf', | |
| content: pdfBase64, | |
| sha: sha | |
| }); | |
| # Second job to build the project and deploy it to Firebase Hosting | |
| build_and_deploy: | |
| if: contains(github.event.head_commit.message, '[ci]') || (contains(github.event.head_commit.message, '[resume]') && needs.build_resume.result == 'success') | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step to checkout the repository | |
| - name: Checkout Repo | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # Step to install Node.js and Yarn | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '16' | |
| - name: Enable Corepack | |
| run: corepack enable | |
| - name: Install dependencies | |
| run: yarn install | |
| - name: Build production bundle | |
| run: yarn build | |
| # Step to deploy to Firebase Hosting | |
| - name: Deploy to Firebase | |
| uses: FirebaseExtended/action-hosting-deploy@v0 | |
| with: | |
| repoToken: '${{ secrets.GITHUB_TOKEN }}' | |
| firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_PORTFOLIO_25124 }}' | |
| projectId: portfolio-25124 | |
| channelId: live |