Build and deploy non-production #136
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 non-production" | |
on: | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
directory: | |
description: 'Directory reference' | |
required: true | |
default: 'main' | |
blogs: | |
description: 'Blogs reference' | |
required: true | |
default: 'main' | |
triggering_issue: | |
description: 'Triggering PR' | |
required: false | |
triggering_repo: | |
description: 'Triggering repo' | |
required: false | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.inputs.directory }} | |
cancel-in-progress: true | |
env: | |
RENV_PROFILE: "dev" | |
RENV_CONFIG_SANDBOX_ENABLED: FALSE | |
issue: ${{ github.event.inputs.triggering_issue || github.event.pull_request.number }} | |
repo_name: ${{ github.event.inputs.triggering_repo || github.repository }} | |
directory: ${{ github.event.inputs.directory || 'main' }} | |
blogs: ${{ github.event.inputs.blogs || 'main' }} | |
rid: ${{ github.event.number || github.run_id }} | |
jobs: | |
build: | |
name: Build site | |
runs-on: ubuntu-latest | |
env: | |
hugobd: public | |
on_fork: ${{ github.event.pull_request.head.repo.fork == true }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Set env parameters | |
run: | | |
ver=$(cat .hugoversion) | |
echo "hugovr=$ver" >> $GITHUB_ENV | |
echo "repo_owner=$(dirname ${{ env.repo_name }})" >> $GITHUB_ENV | |
echo "repo_name=$(basename ${{ env.repo_name }})" >> $GITHUB_ENV | |
echo "netalias=d${{ env.directory }}-b${{ env.blogs }}-r${{ env.rid}}" >> $GITHUB_ENV | |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
echo "token=${{ secrets.GLOBAL_GHA_PAT }}" >> $GITHUB_ENV | |
echo "blogsref=refs/pull/${{ env.issue }}/head" >> $GITHUB_ENV | |
else | |
echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV | |
echo "blogsref=main" >> $GITHUB_ENV | |
fi | |
- name: Install cURL Headers | |
run: | | |
sudo apt-get update | |
sudo apt-get install libcurl4-openssl-dev | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: '4.3.0' | |
- name: Serup renv | |
uses: r-lib/actions/setup-renv@v2 | |
- name: Populate untranslated pages | |
run: | | |
Rscript scripts/missing_translations.R | |
- name: Site data - Clean folders | |
if: ${{ env.on_fork != 'true' }} | |
run: rm -r data/directory data/rblogs | |
- name: Site data - DIRECTORY - Get | |
uses: actions/checkout@v4 | |
if: ${{ (env.on_fork != 'true') && env.directory == 'main' }} | |
with: | |
repository: rladies/directory | |
ssh-key: ${{ secrets.ssh_directoryy_repo }} | |
path: tmpd/dir | |
- name: Site data - DIRECTORY - Download artifact | |
uses: dawidd6/action-download-artifact@v2 | |
if: ${{ (env.on_fork != 'true') && env.directory != 'main' }} | |
with: | |
name: entries | |
github_token: ${{ secrets.GLOBAL_GHA_PAT }} | |
run_id: ${{ env.directory }} | |
repo: rladies/directory | |
path: entries/ | |
- name: Site data - DIRECTORY - Move | |
if: ${{ env.on_fork != 'true' }} | |
run: | | |
rm -rf data/directory/* assets/directory/* | |
if [ "${{ env.directory }}" = "main" ]; then | |
cp -r tmpd/dir/data/json data/directory | |
cp -r tmpd/dir/data/img/* assets/directory | |
else | |
mv entries/json data/directory | |
if [ -d "entries/img" ]; then | |
mv entries/img/* assets/directory | |
fi | |
fi | |
- name: Site data - Get blogs list | |
if: ${{ env.on_fork != 'true' }} | |
uses: actions/checkout@v4 | |
with: | |
repository: rladies/awesome-rladies-blogs | |
ssh-key: ${{ secrets.RLADIES_BLOGS_KEY}} | |
ref: ${{ env.blogsref }} | |
path: tmpd/rblogs | |
- name: Site data - Meetup | |
if: ${{ env.on_fork != 'true' }} | |
uses: actions/checkout@v4 | |
with: | |
repository: rladies/meetup_archive | |
ssh-key: ${{ secrets.MEETUP_ARCHIVE_KEY}} | |
path: tmpd/mtp | |
- name: Site data - clean cloned repos | |
if: ${{ env.on_fork != 'true' }} | |
run: | | |
cp -r tmpd/rblogs/blogs data/rblogs | |
cp -r tmpd/mtp/data/* data/meetup/ | |
rm -rf tmpd | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: ${{ env.hugovr }} | |
extended: true | |
- name: Build | |
run: | | |
hugo \ | |
-e development \ | |
-d ${{ env.hugobd }} \ | |
-b https://${{ env.netalias }}--rladies-dev.netlify.app/ | |
- name: Deploy Preview | |
if: ${{ env.on_fork != 'true' }} | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
run: | | |
npm install netlify-cli -g | |
netlify deploy \ | |
--alias=${{ env.netalias }} \ | |
--dir=${{ env.hugobd }} | |
- uses: actions/github-script@v7 | |
name: "Notify about build failure" | |
if: ${{ failure() }} | |
with: | |
github-token: ${{ env.token }} | |
script: | | |
await github.rest.issues.createComment({ | |
issue_number: ${{ env.issue }}, | |
owner: 'rladies', | |
repo: '${{ env.repo_name }}', | |
body: 'Test build failed :sob: [Check out the build logs](https://github.com/rladies/rladies.github.io/actions/runs/${{ github.run_id }}).' | |
}) | |
- uses: actions/github-script@v7 | |
name: "Notify about build preview" | |
with: | |
github-token: ${{ env.token }} | |
script: | | |
await github.rest.issues.createComment({ | |
issue_number: ${{ env.issue }}, | |
owner: 'rladies', | |
repo: '${{ env.repo_name }}', | |
body: ':tada: The preview is built! [Check it out :eyes:](https://${{ env.netalias }}--rladies-dev.netlify.app)' | |
}) | |