Skip to content

Commit

Permalink
separated restore and deploy jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Jan 24, 2024
1 parent 5beb6cd commit 3c79669
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 130 deletions.
1 change: 0 additions & 1 deletion .github/workflows/_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
- name: Checkout the source repository from Git
uses: actions/checkout@v4

Expand Down
109 changes: 0 additions & 109 deletions .github/workflows/_build-deploy.yml

This file was deleted.

59 changes: 59 additions & 0 deletions .github/workflows/_build-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "Build"

on:
workflow_call:
inputs:
project_path:
description: 'The project file path'
required: true
type: string
project_version:
description: 'The project version'
required: true
type: string
project_output:
description: "Path of the publish output directory"
default: "publish"
type: string

jobs:
build_website:
name: Build
runs-on: 'ubuntu-latest'
env:
NET_VERSION: '8.x'

steps:
- name: Download artifacts from the restore job
uses: actions/download-artifact@v4
with:
path: .

# https://github.com/actions/setup-dotnet
- name: Get .NET ${{ env.NET_VERSION }} externals
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.NET_VERSION }}
dotnet-quality: 'ga'

# https://github.com/dotnet/runtime/blob/main/src/mono/wasm/features.md
- name: Install .NET WebAssembly workload
run: dotnet workload install wasm-tools;
# dotnet workload restore;

- name: Version and publish the project
run: dotnet publish ${{ inputs.project_path }} -c:Release -p:GHPages=true -p:Version=${{ inputs.project_version }} -o:${{ inputs.project_output }} --no-restore --nologo

# "https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-8.0#github-pages"
# "To deploy folders starting with underscore, add an empty .nojekyll file to the Git branch."
- name: Add .nojekyll file
run: touch "${{ inputs.project_output }}/wwwroot/.nojekyll"

- name: Setup Pages
uses: actions/configure-pages@v4

# https://github.com/actions/upload-pages-artifact
- name: Upload GitHub Pages artifact for web
uses: actions/upload-pages-artifact@v3
with:
path: "${{ inputs.project_output }}/wwwroot"
38 changes: 38 additions & 0 deletions .github/workflows/_deploy-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Build"

on:
workflow_call:
inputs:
artifact_name:
description: 'Artifact name'
default: 'github-pages'
type: string
outputs:
page_url:
description: 'The webpage URL'
value: ${{ jobs.deploy_website.outputs.page_url }}

jobs:
deploy_website:
name: Deploy App to GitHub Pages

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: ${{ inputs.artifact_name }}
url: ${{ steps.deployment.outputs.page_url }}

outputs:
page_url: ${{ steps.deployment.outputs.page_url }}

# Specify runner + deployment step
runs-on: ubuntu-latest
steps:
# https://github.com/actions/deploy-pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action
41 changes: 41 additions & 0 deletions .github/workflows/_restore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Restore"

on:
workflow_call:
inputs:
project_name:
description: 'The name of the project'
required: true
type: string
outputs:
project_path:
description: 'The project file path'
value: ${{ jobs.restore.outputs.project_path }}

jobs:
restore:
name: Build
runs-on: 'ubuntu-latest'
env:
PROJECT_PATH: "./${{ inputs.project_name }}/${{ inputs.project_name }}.csproj"
outputs:
project_path: ${{ env.PROJECT_PATH }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

# https://github.com/actions/setup-dotnet
- name: Get .NET externals
uses: actions/setup-dotnet@v4

- name: Restore project dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}

# https://github.com/actions/upload-artifact
- name: Upload version artifacts
uses: actions/upload-artifact@v4
with:
path: .
retention-days: 1
if-no-files-found: error # or 'ignore', defaults to `warn`
28 changes: 14 additions & 14 deletions .github/workflows/_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ run-name: Get version with GitVersion
on:
workflow_call:
inputs:
appProjectName:
description: 'The repository app project name'
project_search:
description: 'The name of the project to search for'
required: false
type: string
outputs:
projectName:
repositoryName:
description: 'The repository app project name'
value: ${{ jobs.version.outputs.projectName }}
value: ${{ jobs.version.outputs.repositoryName }}
projectFile:
description: 'The repository app project file'
value: ${{ jobs.version.outputs.projectFile }}
Expand All @@ -31,7 +31,7 @@ jobs:
majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}
preReleaseLabel: ${{ steps.gitversion.outputs.preReleaseLabel }}
commitDate: ${{ steps.gitversion.outputs.commitDate }}
projectName: ${{ steps.metadata.outputs.projectName }}
repositoryName: ${{ steps.metadata.outputs.repositoryName }}
projectFile: ${{ steps.metadata.outputs.projectFile }}

steps:
Expand All @@ -56,19 +56,18 @@ jobs:

- run: |
echo 'Get the repository project name.'
projectName=$(basename '${{ github.repository }}')
echo "Repository name: $projectName"
echo "projectName=${projectName}" >> $GITHUB_ENV
echo "App project name: ${{ inputs.appProjectName }}"
repositoryName=$(basename '${{ github.repository }}')
echo "Repository name: $repositoryName"
echo "repositoryName=${repositoryName}" >> $GITHUB_ENV
- run: |
echo "Generate release notes from the Git commit log."
echo "## $projectName" > release-notes.txt
echo "## $repositoryName" > release-notes.txt
git log --pretty=format:"- %s" >> release-notes.txt
- run: |
echo 'Save the project name to a file.'
echo "projectName=${projectName}" > version.txt
echo "repositoryName=${repositoryName}" > version.txt
- run: |
echo 'Save the repository solution file path'
Expand All @@ -82,8 +81,9 @@ jobs:
shell: bash
run: |
echo 'Save the main app project file path'
echo "projectName=${projectName}" >> $GITHUB_OUTPUT
searchName="${{ inputs.appProjectName }}"
echo "repositoryName=${repositoryName}" >> $GITHUB_OUTPUT
echo "Project name to search for: ${{ inputs.project_search }}"
searchName="${{ inputs.project_search }}"
for project in ./**/*.csproj; do
echo "Project file: $project"
if [[ $project == *"${searchName}"* ]]; then
Expand All @@ -108,7 +108,7 @@ jobs:
echo 'Full Semantic Version: ${{ steps.gitversion.outputs.fullSemVer }}' >> $GITHUB_STEP_SUMMARY
echo 'Pre-release Label: ${{ steps.gitversion.outputs.preReleaseLabel }}' >> $GITHUB_STEP_SUMMARY
env:
workflowVersion: '${{ steps.metadata.outputs.projectName }} version ${{ steps.gitversion.outputs.semVer }}'
workflowVersion: '${{ steps.metadata.outputs.repositoryName }} version ${{ steps.gitversion.outputs.semVer }}'

# https://github.com/actions/upload-artifact
- name: Upload version artifacts
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ jobs:
version:
uses: ./.github/workflows/_version.yml
with:
appProjectName: "Bible.Web"
project_search: "Bible.*"

restore:
uses: ./.github/workflows/_restore.yml
with:
project_name: "Bible.Web"

build:
needs: [ version, restore ]
uses: ./.github/workflows/_build-web.yml
with:
project_path: ${{ needs.restore.outputs.project_path }}
project_version: ${{ needs.version.outputs.semVer }}

publish:
if: ${{ github.event_name != 'pull_request' }}
needs: version
uses: ./.github/workflows/_build-deploy.yml
with:
project-name: "Bible.Web"
project-version: ${{ needs.version.outputs.semVer }}
needs: [ build ]
uses: ./.github/workflows/_deploy-web.yml
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
Expand Down

0 comments on commit 3c79669

Please sign in to comment.