diff --git a/.github/workflows/_android.yml b/.github/workflows/_android.yml index d9698c7..aac020c 100644 --- a/.github/workflows/_android.yml +++ b/.github/workflows/_android.yml @@ -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 diff --git a/.github/workflows/_build-deploy.yml b/.github/workflows/_build-deploy.yml deleted file mode 100644 index 33d856b..0000000 --- a/.github/workflows/_build-deploy.yml +++ /dev/null @@ -1,109 +0,0 @@ -name: "Build" - -on: - workflow_call: - inputs: - project-name: - description: 'The name of the project' - 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 - name: - description: 'Artifact name' - default: 'github-pages' - type: string - outputs: - project_file: - description: 'The project file name' - value: ${{ jobs.build_website.outputs.project-file }} - page_url: - description: 'The webpage URL' - value: ${{ jobs.deploy.outputs.page_url }} - -jobs: - build_website: - name: Build - runs-on: 'ubuntu-latest' - env: - PROJECT_PATH: "./${{ inputs.project-name }}/${{ inputs.project-name }}.csproj" - NET_VERSION: '8.x' - - outputs: - project-file: ${{ env.PROJECT_PATH }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # 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: Restore project dependencies - run: | - dotnet restore ${{ env.PROJECT_PATH }} - dotnet publish ${{ env.PROJECT_PATH }} -c:Release -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" - - # changes the base-tag in index.html from '/' to match GitHub Pages repository subdirectory - - name: Change base-tag in index.html from / to the repository name - run: | - repositoryName=$(basename '${{ github.repository }}') - echo "Repository name: $repositoryName" - sed -i 's///g' "${{ inputs.project-output }}/wwwroot/index.html" - - - 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" - - # Deploy job - deploy: - name: Deploy App to GitHub Pages - # Add a dependency to the build job - needs: - - build_website - - # 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.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 \ No newline at end of file diff --git a/.github/workflows/_build-web.yml b/.github/workflows/_build-web.yml new file mode 100644 index 0000000..c9e386e --- /dev/null +++ b/.github/workflows/_build-web.yml @@ -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" \ No newline at end of file diff --git a/.github/workflows/_deploy-web.yml b/.github/workflows/_deploy-web.yml new file mode 100644 index 0000000..68b9308 --- /dev/null +++ b/.github/workflows/_deploy-web.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/_restore.yml b/.github/workflows/_restore.yml new file mode 100644 index 0000000..1073f3e --- /dev/null +++ b/.github/workflows/_restore.yml @@ -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` \ No newline at end of file diff --git a/.github/workflows/_version.yml b/.github/workflows/_version.yml index eab2ce7..b552031 100644 --- a/.github/workflows/_version.yml +++ b/.github/workflows/_version.yml @@ -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 }} @@ -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: @@ -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' @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 138a521..e0013f9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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