Simplified workflow definition. #142
Workflow file for this run
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 | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened, closed] | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
BUILD: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'workflow_dispatch' }} | |
DEPLOY: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') }} | |
TAG: ${{ github.event_name == 'push' }} | |
REMOVE_STAGE_SITE: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' }} | |
jobs: | |
build_and_deploy_job: | |
name: Build and Deploy Job | |
runs-on: ubuntu-latest | |
steps: | |
- name: github variable | |
env: | |
CONTENT: ${{ toJson(github) }} | |
run: echo "$CONTENT" | |
- name: BUILD variable | |
run: echo "$BUILD" | |
- name: DEPLOY variable | |
run: echo "$DEPLOY" | |
- name: TAG variable | |
run: echo "$TAG" | |
- name: REMOVE_STAGE_SITE variable | |
run: echo "$REMOVE_STAGE_SITE" | |
- name: Checkout repository | |
if: ${{ env.BUILD }} | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- name: Create tag | |
if: ${{ env.TAG }} | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
const { default: createGitTag } = await import('${{ github.workspace }}/scripts/createGitTag.mjs'); | |
await createGitTag(github, context); | |
- name: Fetch tag | |
if: ${{ env.TAG }} | |
run: git fetch --tags | |
- name: Cache node modules | |
if: ${{ env.DEPLOY }} | |
uses: actions/cache@v3 | |
with: | |
path: ./node_modules | |
key: app-node-modules-${{ hashFiles('./yarn.lock') }} | |
restore-keys: | | |
app-node-modules- | |
- name: Build And Deploy | |
if: ${{ env.BUILD }} | |
uses: Azure/static-web-apps-deploy@v1 | |
with: | |
azure_static_web_apps_api_token: ${{ env.DEPLOY && '' || secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
action: "upload" | |
app_location: "/" | |
api_location: "" | |
output_location: "build" | |
env: | |
SKIP_DEPLOY_ON_MISSING_SECRETS: ${{ !env.DEPLOY }} | |
- name: Remove Pull Request Stage Site | |
if: ${{ env.REMOVE_STAGE_SITE }} | |
uses: Azure/static-web-apps-deploy@v1 | |
with: | |
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} | |
action: "close" | |
app_location: "/" | |
api_location: "" | |
output_location: "build" |