Skip to content

Try to make archive retrival work #174

Try to make archive retrival work

Try to make archive retrival work #174

Workflow file for this run

name: Azure Static Web Apps CI/CD
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
# this hack was stolen from here: https://github.com/orgs/community/discussions/25669
check:
name: Check if main.bicep was touched
outputs:
run_job: ${{ steps.check_files.outputs.run_job }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: check modified files
id: check_files
run: |
echo "=============== list modified files ==============="
git diff --name-only HEAD^ HEAD
echo "========== check paths of modified files =========="
git diff --name-only HEAD^ HEAD > files.txt
while IFS= read -r file
do
echo $file
if [[ $file != main.bicep ]]; then
echo "The file main.bicep was touch, need approval of admin."
echo "::set-output name=run_job::false"
break
else
echo "::set-output name=run_job::true"
fi
done < files.txt
build_and_deploy_job:
if: (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: windows-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Get PR title
id: Pr-Title
run: |
title=$(gh pr view ${{ github.event.number }} --repo ${{ github.repository }} | head -n 1)
echo "::set-output name=pr-title::$(echo $title)"
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
# Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x
dotnet-version: |
7.0.x
6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Publish Frontend
run: dotnet publish -c Release ./src/CZ.Azure.FileExchange/ -o temp/frontend
- name: Publish API
run: dotnet publish -c Release ./src/CZ.Azure.FileExchange.Api/ -o temp/api --runtime win-x86 --no-self-contained
- name: zip outputs
shell: pwsh
run: |
Compress-Archive temp/frontend/wwwroot/** temp/frontend.zip;
Compress-Archive temp/api/** temp/api.zip;
Remove-Item -Recurse -Force temp/frontend
Remove-Item -Recurse -Force temp/api
- name: Add Artifact App
uses: actions/upload-artifact@v3
with:
name: artifact
path: temp/
- name: Add Artifact script
uses: actions/upload-artifact@v3
with:
name: artifact
path: ./build/deploy.ps1
- name: Deploy
id: deploy
run: './build/deploy.ps1 -Token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_KINDDUNE004C2C103 }} -appBuildOutput ./temp/frontend.zip -apiBuildOutput ./temp/api.zip -workingDir $pwd -envrionmentName ${{ github.event.number }} -pullrequestTitle "${{steps.Pr-Title.outputs.pr-title}}" -branchName ${{ github.head_ref }} -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -Verbose'
shell: pwsh
- name: comment-pr
uses: JoseThen/[email protected]
with:
comment: Your website can be viewed here '${{ steps.deploy.outputs.SiteUrl }}'
# Github Token for authentication
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Get PR title
id: Pr-Title
run: |
title=$(gh pr view ${{ github.event.number }} --repo ${{ github.repository }} | head -n 1)
echo "::set-output name=pr-title::$(echo $title)"
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Deploy
run: './build/deploy.ps1 -Token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_KINDDUNE004C2C103 }} -appBuildOutput ./temp/frontend/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName ${{ github.event.number }} -pullrequestTitle "${{steps.Pr-Title.outputs.pr-title}}" -branchName ${{ github.head_ref }} -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -Verbose -Delete'
shell: pwsh
compile_and_deploy_bicep:
needs: check
if: (needs.check.outputs.run_job == 'false')
environment: 'Azure Infra'
runs-on: 'ubuntu-latest'
name: compile main bicep
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: compile bicep
uses: Azure/[email protected]
with:
bicepFilePath: main.bicep
outputFilePath: azuredeploy.json
- name: Login to Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: "Deploy ARM template to Azure"
uses: Azure/arm-deploy@v1
with:
scope: resourcegroup
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: 'pajetestfileshare'
region: 'West Europe'
template: 'azuredeploy.json'
parameters: name=pajetestfileshare
deploymentMode: 'Incremental'
deploy_app_only:
needs: check
runs-on: 'ubuntu-latest'
steps:
- name: download Artifact
uses: actions/download-artifact@v3
with:
name: artifact
- name: Deploy
id: deploy
run: './build/deploy.ps1 -Token ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_KINDDUNE004C2C103 }} -appBuildOutput ./frontend/wwwroot/ -apiBuildOutput ./api/ -envrionmentName ${{ github.event.number }} -pullrequestTitle "${{steps.Pr-Title.outputs.pr-title}}" -branchName ${{ github.head_ref }} -apiFramework "dotnetisolated" -apiFrameworkVersion "7.0" -Verbose'
shell: pwsh
- name: comment-pr
uses: JoseThen/[email protected]
with:
comment: Your website can be viewed here '${{ steps.deploy.outputs.SiteUrl }}'
# Github Token for authentication
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}