Workflows, automation, esbuild #2
This file contains hidden or 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: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened, closed] | |
env: | |
# we call `pnpm playwright install` instead | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" | |
NODE_MATRIX: '["18.x", "20.x"]' | |
# cancel in-progress runs on new commits to same PR (gitub.event.number) | |
# cancel in-progress runs on new pushes to same branch (github.ref_name) | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.number || github.ref_name }} | |
cancel-in-progress: true | |
permissions: | |
contents: read # to fetch code (actions/checkout) | |
# pull-requests: write # to create comments (actions/github-script) | |
jobs: | |
lint: | |
if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: npm | |
cache-dependency-path: ./**/package-lock.json | |
- run: npm ci | |
- run: npm run check-types | |
- run: npm run check-format | |
- run: npm ci | |
working-directory: demo | |
- run: npm run check | |
working-directory: demo | |
define-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
node-versions: ${{ steps.node.outputs.node-versions }} | |
steps: | |
- id: node | |
run: echo "node-versions=$NODE_MATRIX" >> "$GITHUB_OUTPUT" | |
test: | |
needs: define-matrix | |
if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: ${{ fromJson(needs.define-matrix.outputs.node-versions) }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: npm | |
cache-dependency-path: ./**/package-lock.json | |
- run: npm ci | |
- run: npm test | |
test-swa: | |
needs: define-matrix | |
if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: ${{ fromJson(needs.define-matrix.outputs.node-versions) }} | |
defaults: | |
run: | |
working-directory: demo | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: npm | |
cache-dependency-path: ./**/package-lock.json | |
- run: npm ci | |
- run: npx playwright install chromium --with-deps | |
- run: npm run test:swa | |
do-test-azure: | |
runs-on: ubuntu-latest | |
outputs: | |
do-test: ${{ steps.event.outputs.result || steps.token.outputs.result || 'false' }} | |
steps: | |
- id: event | |
if: | | |
github.repository != github.event.pull_request.head.repo.full_name && | |
github.event_name != 'push' | |
run: | | |
echo "github.repository: ${{ github.repository }}" | |
echo "github.event.pull_request.head.repo.full_name: ${{ github.event.pull_request.head.repo.full_name }}" | |
echo "No deployment to azure will be executed" | |
echo "result=false" >> "$GITHUB_OUTPUT" | |
- id: token | |
if: steps.event.outputs.result != 'false' | |
run: | | |
if [ -z "${{ secrets.CI_AZURE_STATIC_WEB_APPS_API_TOKEN }}" ]; then | |
echo "CI_AZURE_STATIC_WEB_APPS_API_TOKEN (secret) is NOT available" | |
echo "No deployment to azure will be executed" | |
# echo "result=false" >> "$GITHUB_OUTPUT" | |
else | |
echo "CI_AZURE_STATIC_WEB_APPS_API_TOKEN (secret) is available" | |
echo "Deployment to azure will be executed" | |
echo "result=true" >> "$GITHUB_OUTPUT" | |
fi | |
# clean-test-azure: | |
# needs: | |
# - do-test-azure | |
# - define-matrix | |
# if: needs.do-test-azure.outputs.do-test == 'true' | |
# runs-on: ubuntu-latest | |
# strategy: | |
# matrix: | |
# node-version: ${{ fromJson(needs.define-matrix.outputs.node-versions) }} | |
# concurrency: | |
# group: ci-clean-test-azure | |
# steps: | |
# - name: pr-deleter | |
# uses: maheshrayas/[email protected] | |
# with: | |
# github_token: "${{ secrets.GITHUB_TOKEN }}" | |
# org: "geoffrich" | |
# repo: "svelte-adapter-azure-swa" | |
# user: "github-actions[bot]" | |
# issue: "${{github.event.number}}" | |
test-azure: | |
needs: | |
- do-test-azure | |
- define-matrix | |
# - clean-test-azure | |
if: ${{ !(github.event_name == 'pull_request' && github.event.action == 'closed') }} | |
concurrency: | |
group: ci-test-azure-${{ github.event.pull_request.head.repo.full_name || github.repository }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: ${{ fromJson(needs.define-matrix.outputs.node-versions) }} | |
defaults: | |
run: | |
working-directory: demo | |
steps: | |
- uses: actions/checkout@v4 | |
if: needs.do-test-azure.outputs.do-test == 'true' | |
- uses: actions/setup-node@v4 | |
if: needs.do-test-azure.outputs.do-test == 'true' | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: npm | |
cache-dependency-path: ./**/package-lock.json | |
- run: npm ci | |
if: needs.do-test-azure.outputs.do-test == 'true' | |
- id: api-runtime | |
if: needs.do-test-azure.outputs.do-test == 'true' | |
run: echo "major=$(node -v | cut -d. -f1 | cut -dv -f2)" >> "$GITHUB_OUTPUT" | |
- uses: ./.github/actions/static-web-apps-deploy-wrapper | |
if: needs.do-test-azure.outputs.do-test == 'true' | |
id: build-deploy | |
env: | |
NODE_API_RUNTIME: node:${{ steps.api-runtime.outputs.major }} | |
with: | |
azure_static_web_apps_api_token: ${{ secrets.CI_AZURE_STATIC_WEB_APPS_API_TOKEN }} | |
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) | |
action: "upload" | |
###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### | |
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig | |
app_location: "/demo" # App source code path | |
api_location: "demo/func" # Api source code path - optional | |
output_location: "build/static" # Built app content directory - optional | |
###### End of Repository/Build Configurations ###### | |
- run: npx playwright install chromium --with-deps | |
if: needs.do-test-azure.outputs.do-test == 'true' | |
- run: npm test | |
if: needs.do-test-azure.outputs.do-test == 'true' | |
env: | |
PLAYWRIGHT_TEST_BASE_URL: ${{ steps.build-deploy.outputs.static_web_app_url }} | |
- id: complete | |
working-directory: ./ | |
# Check if node version is 18.x and write to output complete-node-18 | |
# Check if node version is 20.x and write to output complete-node-20 | |
run: | | |
if [ "${{ matrix.node-version }}" == "18.x" ]; then | |
if [ ${{needs.do-test-azure.outputs.do-test}} == 'true' ]; then | |
echo "complete-node-18=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "complete-node-18=false" >> "$GITHUB_OUTPUT" | |
fi | |
elif [ "${{ matrix.node-version }}" == "20.x" ]; then | |
if [ ${{needs.do-test-azure.outputs.do-test}} == 'true' ]; then | |
echo "complete-node-20=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "complete-node-20=false" >> "$GITHUB_OUTPUT" | |
fi | |
fi | |
outputs: | |
complete-node-18: ${{ steps.complete.outputs.complete-node-18 }} | |
complete-node-20: ${{ steps.complete.outputs.complete-node-20 }} | |
complete-test-azure: | |
needs: test-azure | |
runs-on: ubuntu-latest | |
steps: | |
- run: | | |
echo "complete-node-18=${{ needs.test-azure.outputs.complete-node-18 }}" | |
echo "complete-node-20=${{ needs.test-azure.outputs.complete-node-20 }}" | |
close-azure: | |
needs: do-test-azure | |
if: | | |
needs.do-test-azure.outputs.do-test == 'true' && | |
(github.event_name == 'pull_request' && github.event.action == 'closed') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/static-web-apps-deploy-wrapper | |
with: | |
azure_static_web_apps_api_token: ${{ secrets.CI_AZURE_STATIC_WEB_APPS_API_TOKEN }} | |
action: "close" |