Skip to content

Commit

Permalink
Secretless PR Builds (#641)
Browse files Browse the repository at this point in the history
This PR will add the ability to have trigger PRs with the pull_request
trigger. Having PR builds triggered from the pull_request trigger means
that builds triggered from forks won't have access to secrets.


- [x] Release notes 
- [x] Testing 


PR triggered with "pull_request" from branch:
https://github.com/aholstrup1/ALAppExtensions/actions/runs/5750014584
PR triggered with "pull_request" from fork:
https://github.com/aholstrup1/ALAppExtensions/actions/runs/5750987725/job/15588856379

---------

Co-authored-by: Maria Zhelezova <[email protected]>
  • Loading branch information
aholstrup1 and mazhelez authored Aug 7, 2023
1 parent 78365a5 commit 605b064
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ function ReadSettings {
"environments" = @()
"buildModes" = @()
"useCompilerFolder" = $false
"PullRequestTrigger" = "pull_request_target"
}

# Read settings from files and merge them into the settings object
Expand Down
10 changes: 8 additions & 2 deletions Actions/CheckForUpdates/CheckForUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,22 @@ try {
}
}

# The PullRequestHandler workflow can have a RepoSetting called CICDPullRequestBranches, which will be used to set the branches for the workflow
if ($baseName -eq "PullRequestHandler") {
# The PullRequestHandler workflow can have a RepoSetting called PullRequestTrigger which specifies the trigger to use for Pull Requests
$triggerSection = $yaml.Get('on:/pull')
$triggerSection.content = "$($repoSettings.PullRequestTrigger):"
$yaml.Replace('on:/pull', $triggerSection.Content)

# The PullRequestHandler workflow can have a RepoSetting called CICDPullRequestBranches, which will be used to set the branches for the workflow
if ($repoSettings.Keys -contains 'CICDPullRequestBranches') {
$CICDPullRequestBranches = $repoSettings.CICDPullRequestBranches
}
else {
$CICDPullRequestBranches = $defaultCICDPullRequestBranches
}

# update the branches: line with the new branches
$yaml.Replace('on:/pull_request_target:/branches:', "branches: [ '$($cicdPullRequestBranches -join "', '")' ]")
$yaml.Replace("on:/$($repoSettings.PullRequestTrigger):/branches:", "branches: [ '$($CICDPullRequestBranches -join "', '")' ]")
}

# Repo Setting runs-on and shell determines which GitHub runner is used for all non-build jobs (build jobs are run using the GitHubRunner/GitHubRunnerShell repo settings)
Expand Down
6 changes: 5 additions & 1 deletion Actions/DetermineArtifactUrl/DetermineArtifactUrl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ try {
#region Action: Determine artifacts to use
$telemetryScope = CreateScope -eventId 'DO0084' -parentTelemetryScopeJson $parentTelemetryScopeJson
$secrets = $secretsJson | ConvertFrom-Json | ConvertTo-HashTable
$insiderSasToken = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets.insiderSasToken))
if ($secrets.ContainsKey('insiderSasToken')) {
$insiderSasToken = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets.insiderSasToken))
} else {
$insiderSasToken = ""
}
$projectSettings = $env:Settings | ConvertFrom-Json | ConvertTo-HashTable
$projectSettings = AnalyzeRepo -settings $projectSettings -project $project -doNotCheckArtifactSetting -doNotIssueWarnings
$artifactUrl = Determine-ArtifactUrl -projectSettings $projectSettings -insiderSasToken $insiderSasToken
Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Now, you can set the checkbox called Use GhTokenWorkflow to allowing you to use

### New Settings
- `keyVaultCodesignCertificateName`: With this setting you can delegate the codesigning to an Azure Key Vault. This can be useful if your certificate has to be stored in a Hardware Security Module
- `PullRequestTrigger`: With this setting you can set which trigger to use for Pull Request Builds. By default AL-Go will use pull_request_target.

### New Actions
- `DownloadProjectDependencies`: Downloads the dependency apps for a given project and build mode.
Expand Down
1 change: 1 addition & 0 deletions Scenarios/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The repository settings are only read from the repository settings file (.github
| <a id="useProjectDependencies"></a>useProjectDependencies | Determines whether your projects are built using a multi-stage built workflow or single stage. After setting useProjectDependencies to true, you need to run Update AL-Go System Files and your workflows including a build job will change to have multiple build jobs, depending on each other. The number of build jobs will be determined by the dependency depth in your projects.<br />You can change dependencies between your projects, but if the dependency **depth** changes, AL-Go will warn you that updates for your AL-Go System Files are available and you will need to run the workflow. |
| <a id="CICDPushBranches"></a>CICDPushBranches | CICDPushBranches can be specified as an array of branches, which triggers a CI/CD workflow on commit.<br />Default is [ "main", "release/\*", "feature/\*" ] |
| <a id="CICDPullrequestBranches"></a>CICDPullRequestBranches | CICDPullRequestBranches can be specified as an array of branches, which triggers a CI/CD workflow on a PR.<br />Default is [ "main" ] |
| <a id="PullRequestTrigger"></a>PullRequestTrigger | Setting for specifying the trigger AL-Go should use to trigger Pull Request Builds. By default it is set to [pull_request_target](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) |
| <a id="CICDSchedule"></a>CICDSchedule | CRON schedule for when CI/CD workflow should run. Default is no scheduled run, only manually triggered or triggered by Push or Pull Request. Build your CRON string here: [https://crontab.guru](https://crontab.guru) |
| <a id="UpdateGitHubGoSystemFilesSchedule"></a>UpdateGitHubGoSystemFilesSchedule | CRON schedule for when Update AL-Go System Files should run. When Update AL-Go System Files runs on a schedule, it uses direct COMMIT instead of creating a PR. Default is no scheduled run, only manual trigger. Build your CRON string here: [https://crontab.guru](https://crontab.guru) |
| <a id="buildModes"></a>buildModes | A list of build modes to use when building the AL-Go projects. Every AL-Go projects will be built using each built mode. Available build modes are:<br /> **Default**: Apps are compiled as they are in the source code.<br />**Clean**: _PreprocessorSymbols_ are enabled when compiling the apps. The values for the symbols correspond to the `cleanModePreprocessorSymbols` setting of the AL-Go project.<br />**Translated**: `TranslationFile` compiler feature is enabled when compiling the apps. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:

jobs:
PregateCheck:
if: github.event.pull_request.base.repo.full_name != github.event.pull_request.head.repo.full_name
if: (github.event.pull_request.base.repo.full_name != github.event.pull_request.head.repo.full_name) && (github.event_name != 'pull_request')
runs-on: [ windows-latest ]
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
get: useCompilerFolder,keyVaultCodesignCertificateName,doNotSignApps

- name: Read secrets
if: github.event_name != 'pull_request'
uses: microsoft/AL-Go-Actions/ReadSecrets@main
env:
secrets: ${{ toJson(secrets) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:

jobs:
PregateCheck:
if: github.event.pull_request.base.repo.full_name != github.event.pull_request.head.repo.full_name
if: (github.event.pull_request.base.repo.full_name != github.event.pull_request.head.repo.full_name) && (github.event_name != 'pull_request')
runs-on: [ windows-latest ]
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
get: useCompilerFolder,keyVaultCodesignCertificateName,doNotSignApps

- name: Read secrets
if: github.event_name != 'pull_request'
uses: microsoft/AL-Go-Actions/ReadSecrets@main
env:
secrets: ${{ toJson(secrets) }}
Expand Down

0 comments on commit 605b064

Please sign in to comment.