Build and Deploy #126
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
name: Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
schedule: | |
- cron: 0 0 * * 0 | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
persist-credentials: false | |
- name: Fix URLs for PR preview deployment (pull request previews) | |
if: github.event_name == 'pull_request' | |
run: | | |
echo "PREVIEW_FRANKLIN_WEBSITE_URL=https://tutorial-template.netlify.app/previews/PR${{ github.event.number }}/" >> $GITHUB_ENV | |
echo "PREVIEW_FRANKLIN_PREPATH=previews/PR${{ github.event.number }}" >> $GITHUB_ENV | |
# NOTE: Python is necessary for the pre-rendering (minification) step | |
- name: Install python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.9' | |
# NOTE: Here you can install dependencies such as matplotlib if you use | |
# packages such as PyPlot. | |
# - run: pip install matplotlib | |
- name: Install Julia | |
uses: julia-actions/setup-julia@v1 | |
with: | |
version: 1 | |
- name: Get dependencies from JuliaSmoothOptimizers.github.io | |
run: bash getdeps.sh | |
- name: DEBUG | |
run: echo ">>$CI" | |
- name: Build | |
env: | |
GKSwstype: "100" #https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988 | |
run: julia -e ' | |
using Pkg; Pkg.activate("."); Pkg.instantiate(); | |
using NodeJS; run(`$(npm_cmd()) install`); run(`$(npm_cmd()) run css-build`); | |
using Franklin; | |
optimize(prerender=false, suppress_errors=false)' | |
- name: Deploy (preview) | |
if: github.event_name == 'pull_request' && github.repository == github.event.pull_request.head.repo.full_name # if this build is a PR build and the PR is NOT from a fork | |
uses: JamesIves/github-pages-deploy-action@releases/v3 | |
with: | |
BRANCH: gh-preview # The branch where the PRs previews are stored | |
FOLDER: __site | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TARGET_FOLDER: "previews/PR${{ github.event.number }}" # The website preview is going to be stored in a subfolder | |
- name: Deploy (main) | |
if: github.event_name != 'pull_request' | |
uses: JamesIves/github-pages-deploy-action@releases/v3 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BRANCH: gh-pages # Replace here the branch where your website is deployed | |
FOLDER: __site | |
pr_comment: | |
needs: build-and-deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: 'Comment PR' | |
uses: actions/[email protected] | |
if: github.event_name == 'pull_request' && github.repository == github.event.pull_request.head.repo.full_name # if this is a pull request build AND the pull request is NOT made from a fork | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { issue: { number: issue_number }, repo: { owner, repo } } = context; | |
github.issues.createComment({ issue_number, owner, repo, body: 'Once the build has completed, you can preview your PR at this URL: https://tutorial-template.netlify.app/previews/PR${{ github.event.number }}/' }); |