Prepare Static App #1054
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: Prepare Static App | |
on: | |
push: | |
branches: [ main ] | |
paths: workables/** | |
schedule: | |
- cron: '0 3 * * *' # run at 03 AM UTC | |
workflow_dispatch: | |
jobs: | |
build-static-app: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout-code | |
uses: actions/[email protected] | |
- name: setup-dotnet | |
uses: actions/setup-dotnet@v2 | |
with: | |
dotnet-version: 8.0.x | |
- name: build-builder | |
run: dotnet build ./_src/Blog.Builder.sln --configuration Release | |
- name: publish-builder | |
run: dotnet publish ./_src/Blog.Builder.sln --configuration Release --output tmp | |
- name: build-output | |
run: | | |
cd tmp | |
dotnet Blog.Builder.dll --workables ../workables --output ../_output | |
- name: push-output | |
id: push_output | |
run: | | |
cd _output | |
branchbasename=build-$(date +"%Y.%m.%d-%H.%M.%S")-${{ github.run_number }} | |
branchname=feature/${branchbasename} | |
git config user.name blogbot | |
git config user.email [email protected] | |
git pull | |
git branch ${branchname} | |
git push --set-upstream origin ${branchname} | |
git checkout ${branchname} | |
git add . | |
git commit --allow-empty -m "Automated static files build" | |
git push | |
echo "::set-output name=branchname::${branchname}" | |
- name: pull-request | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
title = '[User Added Content] User ${{ github.actor }} has added new content that is ready to be published.' | |
if( '${{ github.event_name }}' == 'schedule' ) { | |
title = '[Nightly Build] Automated publishment triggered by a schedule.' | |
} | |
if( '${{ github.event_name }}' == 'workflow_dispatch' ) { | |
title = '[Manual Trigger] User ${{ github.actor }} triggered this workflow.' | |
} | |
const { repo, owner } = context.repo; | |
const pr = await github.rest.pulls.create({ | |
title: title, | |
owner, | |
repo, | |
head: '${{ steps.push_output.outputs.branchname }}', | |
base: 'main', | |
body: [ | |
'This PR is auto-generated by', | |
'[actions/github-script](https://github.com/actions/github-script).' | |
].join('\n') | |
}); | |
github.rest.issues.addLabels({ | |
owner, | |
repo, | |
issue_number: pr.data.number, | |
labels: ['${{ github.event_name }}', 'automated-pr'] | |
}); | |
if( '${{ github.event_name }}' == 'schedule' ) { | |
github.rest.pulls.merge({ | |
owner, | |
repo, | |
pull_number: pr.data.number, | |
}); | |
} | |
# When you use the repository's GITHUB_TOKEN to perform tasks, | |
# events triggered by the GITHUB_TOKEN will not create a new workflow run. | |
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow | |
- name: deploy | |
uses: Azure/static-web-apps-deploy@v1 | |
if: ${{ github.event_name }} == 'schedule' | |
with: | |
azure_static_web_apps_api_token: ${{ secrets.AZURE_DEPLOYMENT_TOKEN }} | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
action: "upload" | |
app_location: "/_output" | |