|
| 1 | +name: build |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + tags: |
| 7 | + - '*' |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + forcePublish: |
| 14 | + description: When true the Publish stage will always be run, otherwise it only runs for tagged versions. |
| 15 | + required: false |
| 16 | + default: false |
| 17 | + type: boolean |
| 18 | + skipCleanup: |
| 19 | + description: When true the pipeline clean-up stage will not be run. For example, the cache used between pipeline stages will be retained. |
| 20 | + required: false |
| 21 | + default: false |
| 22 | + type: boolean |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 26 | + cancel-in-progress: true |
| 27 | + |
| 28 | +permissions: |
| 29 | + actions: write # enable cache clean-up |
| 30 | + checks: write # enable test result annotations |
| 31 | + contents: write # enable creating releases |
| 32 | + issues: read |
| 33 | + packages: write # enable publishing packages |
| 34 | + pull-requests: write # enable test result annotations |
| 35 | + |
| 36 | +jobs: |
| 37 | + prepareConfig: |
| 38 | + name: Prepare Configuration |
| 39 | + runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + RESOLVED_ENV_VARS: ${{ steps.prepareEnvVarsAndSecrets.outputs.environmentVariablesYamlBase64 }} |
| 42 | + RESOLVED_SECRETS: ${{ steps.prepareEnvVarsAndSecrets.outputs.secretsYamlBase64 }} |
| 43 | + steps: |
| 44 | + # Declare any environment variables and/or secrets that need to be available inside the build process |
| 45 | + - uses: endjin/Endjin.RecommendedPractices.GitHubActions/actions/prepare-env-vars-and-secrets@main |
| 46 | + id: prepareEnvVarsAndSecrets |
| 47 | + with: |
| 48 | + # BUILDVAR_NuGetPublishSource: |
| 49 | + # When publishing NuGet packages only tagged versions get pushed to nuget.org, otherwise |
| 50 | + # they are pushed to GitHub Packages |
| 51 | + # BUILDVAR_UseAcrTasks: |
| 52 | + # Due to the build phases running as separate jobs the container images built via 'docker build' |
| 53 | + # in the Package phase are not available to the Publish phase. Therefore, we use ACR Tasks to |
| 54 | + # build the images instead. |
| 55 | + environmentVariablesYaml: | |
| 56 | + BUILDVAR_NuGetPublishSource: "${{ startsWith(github.ref, 'refs/tags/') && 'https://api.nuget.org/v3/index.json' || 'https://nuget.pkg.github.com/endjin/index.json' }}" |
| 57 | + BUILDVAR_ContainerRegistryFqdn: endjin.azurecr.io |
| 58 | + BUILDVAR_UseAcrTasks: true |
| 59 | + secretsYaml: | |
| 60 | + NUGET_API_KEY: "${{ startsWith(github.ref, 'refs/tags/') && secrets.ENDJIN_NUGET_APIKEY || secrets.ENDJIN_GITHUB_PUBLISHER_PAT }}" |
| 61 | +
|
| 62 | + build: |
| 63 | + needs: prepareConfig |
| 64 | + uses: endjin/Endjin.RecommendedPractices.GitHubActions/.github/workflows/scripted-build-matrix-pipeline.yml@main |
| 65 | + with: |
| 66 | + netSdkVersion: '8.x' |
| 67 | + # workflow_dispatch inputs are always strings, the type property is just for the UI |
| 68 | + forcePublish: ${{ github.event.inputs.forcePublish == 'true' }} |
| 69 | + skipCleanup: ${{ github.event.inputs.skipCleanup == 'true' }} |
| 70 | + |
| 71 | + # These pass arbitrary environment variables to each of the build pipeline phases, |
| 72 | + # as defined in the 'environmentVariablesYaml' property above. |
| 73 | + compilePhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }} |
| 74 | + testPhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }} |
| 75 | + testPhaseMatrixJson: | |
| 76 | + { |
| 77 | + "os": ["ubuntu-latest", "windows-latest"], |
| 78 | + "dotnetFramework": ["net8.0"], |
| 79 | + "exclude": [] |
| 80 | + } |
| 81 | + packagePhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }} |
| 82 | + publishPhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }} |
| 83 | + secrets: |
| 84 | + # Ensures the build pipeline has access to pull images from the ACR and write SBOMs to storage |
| 85 | + compilePhaseAzureCredentials: ${{ secrets.ENDJIN_PROD_ACR_READER_CREDENTIALS }} |
| 86 | + # Ensures the build pipeline has access to run ACR Tasks |
| 87 | + packagePhaseAzureCredentials: ${{ secrets.ENDJIN_PROD_ACR_PUBLISH_CREDENTIALS }} |
| 88 | + # Ensures the build pipeline has access to push/re-tag images to the ACR |
| 89 | + publishPhaseAzureCredentials: ${{ secrets.ENDJIN_PROD_ACR_PUBLISH_CREDENTIALS }} |
| 90 | + |
| 91 | + # Uncomment the following to pass arbitrary secrets to the required build pipeline phases, |
| 92 | + # as defined in the 'secretsYaml' property above. They will be available to the |
| 93 | + # scripted build process as environment variables. |
| 94 | + # |
| 95 | + # compilePhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }} |
| 96 | + # testPhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }} |
| 97 | + packagePhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }} |
| 98 | + publishPhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }} |
0 commit comments