Integrate theme builder (#267) #117
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: DeployDocs | |
# Controls when the action will run. Triggers the workflow on push to main branch | |
# events but only for the main branch | |
on: | |
push: | |
branches: | |
# Push events on `main` branch | |
- main | |
- '[0-9]+.[0-9]+.[0-9]+' | |
paths: | |
- 'src/**' | |
- 'gatsby-config.js' | |
# For manually triggering the build | |
workflow_dispatch: | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "deploy" | |
deploy: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
# ENV variables that will be used | |
env: | |
GH_TOKEN: ${{ secrets.GATSBY_PUBLISH_SECRET_KEY }} | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# extract branch name | |
- name: Extract branch name | |
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | |
id: extract_branch | |
# Add build env for Prod | |
- name: Add build Env for Prod | |
if: ${{ env.BRANCH_NAME == 'release' }} | |
run: echo "BUILD_ENV=PROD" >> $GITHUB_ENV | |
# Add build env for Dev/Staging | |
- name: Add build Env for Dev/Staging | |
if: ${{ env.BRANCH_NAME == 'main' }} | |
run: echo "BUILD_ENV=DEV" >> $GITHUB_ENV | |
# Check the branch is new release versions | |
- name: Check branch name for release versions | |
id: check-release-brnch-version | |
run: | | |
if [[ ${{ env.BRANCH_NAME }} =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then | |
echo ::set-output name=match::true | |
fi | |
# extract destination dir | |
- name: Extract destination dir name | |
id: extract-destination-dir | |
uses: actions/github-script@v4 | |
env: | |
BRANCH_NAME: '${{env.BRANCH_NAME}}' | |
with: | |
result-encoding: string | |
script: | | |
const branch = process.env.BRANCH_NAME | |
if (branch === 'release') { | |
return 'release' | |
} | |
if (branch === 'main') { | |
return 'dev' | |
} | |
return branch.match(/[0-9]+.[0-9]+/) ? branch.match(/[0-9]+.[0-9]+/).toString() : branch | |
# Add build env for release versions | |
- name: Add build Env for Prod | |
if: steps.check-release-brnch-version.outputs.match == 'true' | |
run: | | |
echo "BUILD_ENV=PROD_VERSIONING" >> $GITHUB_ENV | |
echo "BUILD_DIR=${{steps.extract-destination-dir.outputs.result}}" >> $GITHUB_ENV | |
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | |
- uses: actions/checkout@v2 | |
# Use NodeJS v12.18.3 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '14.15.4' | |
# Run npm install | |
- name: Run npm install | |
run: npm install | |
- name: create env file | |
run: | | |
touch .env | |
echo ALGOLIA_ADMIN_KEY=${{ secrets.ENGINE_API_KEY }} >> .env | |
echo GATSBY_ALGOLIA_SEARCH_KEY=${{ secrets.GATSBY_ALGOLIA_SEARCH_KEY }} >> .env | |
echo GATSBY_ALGOLIA_APP_ID=${{ secrets.GATSBY_ALGOLIA_APP_ID }} >> .env | |
echo BUILD_ENV=LOCAL >> .env | |
# Deploy on github pages | |
- name: build | |
run: npm run build:gatsby | |
# Deploy on github pages | |
- name: publish-release-version | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./public | |
destination_dir: ./${{ steps.extract-destination-dir.outputs.result }} |