From ecb230659712afcb60ad78830fe3d309a481e960 Mon Sep 17 00:00:00 2001 From: Christo du Toit Date: Mon, 25 Nov 2024 18:43:01 +0000 Subject: [PATCH] CODE RUB: Fixed formatting issues and regenerated the build.yml --- .github/workflows/build.yml | 8 +- ADotNet.Infrastructure.Build/Program.cs | 4 +- ADotNet.sln | 1 + .../GithubPipelines/DotNets/LabelJob.cs | 2 + .../GithubPipelines/DotNets/LabelJobV2.cs | 123 +++++++++--------- .../GithubPipelines/DotNets/PublishJob.cs | 3 +- 6 files changed, 73 insertions(+), 68 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 41a2df7..258b06c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,9 +33,8 @@ jobs: - name: Apply Label uses: actions/github-script@v6 with: - github-token: ${{ secrets.PAT_FOR_TAGGING }} - script: >2+ - + github-token: ${{ secrets.GITHUB_TOKEN }} + script: >- const prefixes = [ 'INFRA:', 'PROVISIONS:', @@ -99,6 +98,9 @@ jobs: break; } } + permissions: + contents: read + pull-requests: write build: runs-on: ubuntu-latest steps: diff --git a/ADotNet.Infrastructure.Build/Program.cs b/ADotNet.Infrastructure.Build/Program.cs index e8da9a5..b800cf7 100644 --- a/ADotNet.Infrastructure.Build/Program.cs +++ b/ADotNet.Infrastructure.Build/Program.cs @@ -47,9 +47,7 @@ static void Main(string[] args) { { "label", - new LabelJob( - runsOn: BuildMachines.UbuntuLatest, - githubToken: "${{ secrets.PAT_FOR_TAGGING }}") + new LabelJobV2(runsOn: BuildMachines.UbuntuLatest) }, { "build", diff --git a/ADotNet.sln b/ADotNet.sln index c201826..0bb8550 100644 --- a/ADotNet.sln +++ b/ADotNet.sln @@ -14,6 +14,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{16CB1804-3040-41F0-9C1F-99A139B24873}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + .github\workflows\build.yml = .github\workflows\build.yml EndProjectSection EndProject Global diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJob.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJob.cs index 85569cf..6e77f7f 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJob.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJob.cs @@ -4,6 +4,7 @@ // See License.txt in the project root for license information. // --------------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.ComponentModel; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; @@ -11,6 +12,7 @@ namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets { + [Obsolete("This job is now obsolete. Please migrate to LabelJobV2.")] public sealed class LabelJob : Job { public LabelJob( diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJobV2.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJobV2.cs index 145913a..15b84a4 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJobV2.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/LabelJobV2.cs @@ -32,69 +32,70 @@ public LabelJobV2(string runsOn) With = new Dictionary { { "github-token", "${{ secrets.GITHUB_TOKEN }}" }, - { "script", @" -const prefixes = [ - 'INFRA:', - 'PROVISIONS:', - 'RELEASES:', - 'DATA:', - 'BROKERS:', - 'FOUNDATIONS:', - 'PROCESSINGS:', - 'ORCHESTRATIONS:', - 'COORDINATIONS:', - 'MANAGEMENTS:', - 'AGGREGATIONS:', - 'CONTROLLERS:', - 'CLIENTS:', - 'EXPOSERS:', - 'PROVIDERS:', - 'BASE:', - 'COMPONENTS:', - 'VIEWS:', - 'PAGES:', - 'ACCEPTANCE:', - 'INTEGRATIONS:', - 'CODE RUB:', - 'MINOR FIX:', - 'MEDIUM FIX:', - 'MAJOR FIX:', - 'DOCUMENTATION:', - 'CONFIG:', - 'STANDARD:', - 'DESIGN:', - 'BUSINESS:' -]; - -const pullRequest = context.payload.pull_request; - -if (!pullRequest) { - console.log('No pull request context available.'); - return; -} - -const title = context.payload.pull_request.title; -const existingLabels = context.payload.pull_request.labels.map(label => label.name); - -for (const prefix of prefixes) { - if (title.startsWith(prefix)) { - const label = prefix.slice(0, -1); - if (!existingLabels.includes(label)) { - console.log(`Applying label: ${label}`); - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - labels: [label] - }); - } - break; - } -} -" } + { "script", """ + const prefixes = [ + 'INFRA:', + 'PROVISIONS:', + 'RELEASES:', + 'DATA:', + 'BROKERS:', + 'FOUNDATIONS:', + 'PROCESSINGS:', + 'ORCHESTRATIONS:', + 'COORDINATIONS:', + 'MANAGEMENTS:', + 'AGGREGATIONS:', + 'CONTROLLERS:', + 'CLIENTS:', + 'EXPOSERS:', + 'PROVIDERS:', + 'BASE:', + 'COMPONENTS:', + 'VIEWS:', + 'PAGES:', + 'ACCEPTANCE:', + 'INTEGRATIONS:', + 'CODE RUB:', + 'MINOR FIX:', + 'MEDIUM FIX:', + 'MAJOR FIX:', + 'DOCUMENTATION:', + 'CONFIG:', + 'STANDARD:', + 'DESIGN:', + 'BUSINESS:' + ]; + + const pullRequest = context.payload.pull_request; + + if (!pullRequest) { + console.log('No pull request context available.'); + return; + } + + const title = context.payload.pull_request.title; + const existingLabels = context.payload.pull_request.labels.map(label => label.name); + + for (const prefix of prefixes) { + if (title.startsWith(prefix)) { + const label = prefix.slice(0, -1); + if (!existingLabels.includes(label)) { + console.log(`Applying label: ${label}`); + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: [label] + }); + } + break; + } + } + """ + } } }, - }; + }; } [YamlMember(Order = 0, DefaultValuesHandling = DefaultValuesHandling.OmitDefaults)] diff --git a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/PublishJob.cs b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/PublishJob.cs index 408ce26..d8a0ed8 100644 --- a/ADotNet/Models/Pipelines/GithubPipelines/DotNets/PublishJob.cs +++ b/ADotNet/Models/Pipelines/GithubPipelines/DotNets/PublishJob.cs @@ -4,10 +4,10 @@ // See License.txt in the project root for license information. // --------------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.ComponentModel; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks; -using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV1s; using ADotNet.Models.Pipelines.GithubPipelines.DotNets.Tasks.SetupDotNetTaskV3s; using YamlDotNet.Serialization; @@ -15,6 +15,7 @@ namespace ADotNet.Models.Pipelines.GithubPipelines.DotNets { public class PublishJob : Job { + [Obsolete("This job is now obsolete. Please migrate to PublishJobV2.")] public PublishJob( string runsOn, string dependsOn,