Skip to content

Commit

Permalink
ci: fix workflows (#73)
Browse files Browse the repository at this point in the history
* fix: azure ci

* Update deployment.yml
  • Loading branch information
sheeplin authored Jan 10, 2023
1 parent 7d75b7f commit a94c038
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 23 deletions.
27 changes: 4 additions & 23 deletions .github/workflows/azure-static-web-apps-happy-dune-06c336600.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,19 @@ name: Azure Static Web Apps CI/CD

on:
push:
branches: [ master ]
branches: [master]
pull_request_target:
types: [opened, synchronize, reopened, closed]
types: [closed]

permissions:
contents: read

jobs:
test-build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.x"
cache: "yarn"
- name: Install Dependencies
run: |
yarn install --frozen-lockfile --production=false
- name: Lint
run: |
yarn run lint
- name: Build
run: |
yarn run build
build_and_deploy_job:
needs: test-build
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: write # for Azure/static-web-apps-deploy to comment on PRs
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
if: github.event_name == 'push'
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
Expand All @@ -58,7 +39,7 @@ jobs:
close_pull_request_job:
permissions:
contents: none
if: github.event_name == 'pull_request' && github.event.action == 'closed'
if: github.event_name == 'pull_request_target' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Deployment
# read-write repo token
# access to secrets
on:
workflow_run:
workflows: ["Receive PR"]
types:
- completed

jobs:
upload:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: "Download artifact"
uses: actions/[email protected]
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
- run: unzip pr.zip

- name: "Save PR number to env.number"
run: echo "number=$(cat ./pr/NR)" >> $GITHUB_ENV

- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_HAPPY_DUNE_06C336600 }}
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: "dist" # App source code path
output_location: "dist" # Built app content directory - optional
deployment_environment: ${{ env.number }}
###### End of Repository/Build Configurations ########

- name: Comment URL on PR
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
var issue_number = Number(fs.readFileSync('./pr/NR'));
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: 'This PR is deployed at ${{ steps.builddeploy.outputs.static_web_app_url }}'
});
42 changes: 42 additions & 0 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Receive PR

on:
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "16.x"
cache: "yarn"
- name: Install Dependencies
run: |
yarn install --frozen-lockfile --production=false
- name: Lint
run: |
yarn run lint
- name: Build
run: |
yarn run build-dev
- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
- uses: actions/upload-artifact@v3
with:
name: pr
path: |
./pr/NR
./dist

0 comments on commit a94c038

Please sign in to comment.