build(deps): bump actions #41
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: 🛸 Advanced - Deploy NextJS starter to Azure Static Web App | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
types: [opened, synchronize, reopened, closed] | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build: | |
if: github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: setup node | |
uses: actions/setup-node@v4 | |
with: | |
cache: npm | |
- name: npm install | |
run: npm install | |
- name: npm build | |
run: npm run build | |
- name: tar output | |
run: tar -czvf output.tar.gz ./out/* | |
- name: upload build artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build | |
path: output.tar.gz | |
# todo: do i need to parse branch name for pr's to remove any special chars? | |
deploy: | |
if: github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
needs: build | |
environment: | |
name: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'production' }} | |
url: ${{ steps.deploy.outputs.url }} | |
concurrency: | |
group: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'production' }} | |
cancel-in-progress: false | |
steps: | |
- name: download build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: build | |
- name: extract output | |
run: tar -xzf output.tar.gz | |
- name: install swa cli | |
run: npm install -g @azure/static-web-apps-cli | |
- name: deploy app | |
id: deploy | |
run: | | |
# deploy site with swa | |
set -o pipefail | |
swa deploy ./out --deployment-token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} \ | |
--env ${{ github.event_name == 'pull_request' && format('pr{0}', github.event.number) || 'production' }} 2>&1 | tee deploy.log | |
url=$(grep 'Project deployed to' deploy.log | awk '{print $5}' | sed 's/\x1b\[[0-9;]*m//g') | |
echo "url=$url" >> "$GITHUB_OUTPUT" | |
delete-pr-env: | |
if: github.event_name == 'pull_request' && github.event.action == 'closed' | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
id-token: write | |
steps: | |
- uses: actions/create-github-app-token@v2 | |
id: app-token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.PRIVATE_KEY }} | |
- name: Azure login | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ vars.AZURE_CLIENT_ID }} | |
tenant-id: ${{ vars.AZURE_TENANT_ID }} | |
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }} | |
- name: delete environment | |
env: | |
GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
# destroy static web app environment | |
az staticwebapp environment delete -n nextjs-starter --environment-name ${{ format('pr{0}', github.event.number) }} --yes | |
gh api --method DELETE "/repos/${{ github.repository }}/environments/${{ format('pr-{0}', github.event.number) }}" |