Deploy website #27
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: Deploy website | |
on: workflow_dispatch | |
concurrency: | |
group: website-deployer | |
cancel-in-progress: true | |
permissions: | |
contents: write | |
jobs: | |
versioning: | |
name: Define version | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.marker.outputs.version }} | |
steps: | |
- name: Define marker | |
id: marker | |
run: echo "version=$(date +'%Y.%m.%d')-${{ github.run_number }}" >> $GITHUB_OUTPUT | |
- name: Summary output | |
run: | | |
{ | |
echo "| Info | Value |" | |
echo "| :--- | :---- |" | |
echo "| Version | ${{ steps.marker.outputs.version }} |" | |
} >> $GITHUB_STEP_SUMMARY | |
build-backend: | |
name: Build backend | |
runs-on: ubuntu-latest | |
needs: | |
- versioning | |
env: | |
url: https://charts.stockindicators.dev | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "9.x" | |
dotnet-quality: "ga" | |
- name: Replace cache markers | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: "YYYY.MM.DD" | |
replace: "${{ needs.versioning.outputs.version }}" | |
regex: false | |
- name: Build .NET solution | |
run: > | |
dotnet build server/ChartBackend.sln | |
--configuration Release | |
--property:ContinuousIntegrationBuild=true | |
-warnAsError | |
- name: Package Web API | |
working-directory: server | |
run: > | |
dotnet publish WebApi/WebApi.csproj | |
--configuration Release | |
--property:PublishDir="../artifacts/api" | |
- name: Package Functions | |
working-directory: server | |
run: > | |
dotnet publish Functions/Functions.csproj | |
--configuration Release | |
--property:PublishDir="../artifacts/fns" | |
- name: Save Web API | |
uses: actions/upload-artifact@v4 | |
with: | |
name: api | |
path: "server/artifacts/api" | |
include-hidden-files: true | |
- name: Save Functions | |
uses: actions/upload-artifact@v4 | |
with: | |
name: fns | |
path: "server/artifacts/fns" | |
include-hidden-files: true | |
build-website: | |
name: Build website | |
runs-on: ubuntu-latest | |
needs: | |
- versioning | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "lts/*" | |
cache: "npm" | |
cache-dependency-path: client/package-lock.json | |
- name: Install dependencies | |
working-directory: client | |
run: npm install | |
- name: Replace cache markers | |
uses: jacobtomlinson/gha-find-replace@v3 | |
with: | |
find: "YYYY.MM.DD" | |
replace: "${{ needs.versioning.outputs.version }}" | |
regex: false | |
- name: Update configs | |
shell: pwsh | |
working-directory: client/src | |
run: | | |
(Get-Content index.html).Replace("__GaTag__", "G-17DX6ZW6HP") | Set-Content index.html | |
Write-Host "... Done!" | |
- name: Build site | |
working-directory: client | |
run: npm run build.prod | |
- name: Save artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: web | |
path: client/dist/app/browser | |
include-hidden-files: true | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: | |
- versioning | |
- build-backend | |
- build-website | |
environment: | |
name: charts.stockindicators.dev | |
url: "https://charts.stockindicators.dev" | |
steps: | |
- name: Download Functions package | |
uses: actions/download-artifact@v4 | |
with: | |
name: fns | |
path: artifacts/fns | |
- name: Download API package | |
uses: actions/download-artifact@v4 | |
with: | |
name: api | |
path: artifacts/api | |
- name: Download Web package | |
uses: actions/download-artifact@v4 | |
with: | |
name: web | |
path: artifacts/web | |
- name: Deploy Functions | |
uses: Azure/functions-action@v1 | |
with: | |
app-name: stock-charts-functions | |
package: artifacts/fns | |
publish-profile: ${{ secrets.PUBLISH_PROFILE_FNS }} | |
- name: Deploy API | |
uses: azure/webapps-deploy@v3 | |
with: | |
app-name: stock-charts-api | |
package: artifacts/api | |
publish-profile: ${{ secrets.PUBLISH_PROFILE_API }} | |
- name: Publish to Cloudflare Pages | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_KEY }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
wranglerVersion: "latest" | |
command: > | |
pages deploy artifacts/web | |
--project-name=${{ vars.CLOUDFLARE_PROJECT_NAME }} | |
- name: Tag and draft release note | |
uses: ncipollo/release-action@v1 | |
if: github.ref == 'refs/heads/main' | |
with: | |
body: | | |
We’ve updated [charts.stockindicators.dev](https://charts.stockindicators.dev) | |
generateReleaseNotes: true | |
draft: true | |
tag: ${{ needs.versioning.outputs.version }} | |
commit: ${{ github.ref_name }} |