Skip to content

Commit 6a343fe

Browse files
committed
fix(workflows): simplify conditional commands and improve cache handling
Updated GitHub Actions workflows to remove unnecessary use of `format` in cache-dependent commands. Simplified command logic for `.atom` operations across all workflow files. Added conditional execution for `BuildAtom` when cache is not restored. Adjusted `IBuildTargets` to move all files to the cached directory, ensuring proper handling of all output files during the caching process.
1 parent 48abb06 commit 6a343fe

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

.github/workflows/Build.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
- name: SetupBuildInfo
4848
id: SetupBuildInfo
49-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} SetupBuildInfo --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- SetupBuildInfo --skip --headless' }}
49+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom SetupBuildInfo --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- SetupBuildInfo --skip --headless' }}
5050
env:
5151
pull-request-number: ${{ github.event.number }}
5252

@@ -76,7 +76,8 @@ jobs:
7676

7777
- name: BuildAtom
7878
id: BuildAtom
79-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} BuildAtom --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- BuildAtom --skip --headless' }}
79+
if: steps.cache-restore-atom-build.outputs.cache-hit != true
80+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom BuildAtom --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- BuildAtom --skip --headless' }}
8081
env:
8182
job-runs-on: ${{ matrix.job-runs-on }}
8283
build-slice: ${{ matrix.job-runs-on }}
@@ -117,7 +118,7 @@ jobs:
117118

118119
- name: PackProjects
119120
id: PackProjects
120-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} PackProjects --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- PackProjects --skip --headless' }}
121+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom PackProjects --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- PackProjects --skip --headless' }}
121122

122123
- name: Upload DecSm.Atom
123124
uses: actions/upload-artifact@v4
@@ -187,7 +188,7 @@ jobs:
187188

188189
- name: PackTool
189190
id: PackTool
190-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} PackTool --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- PackTool --skip --headless' }}
191+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom PackTool --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- PackTool --skip --headless' }}
191192
env:
192193
job-runs-on: ${{ matrix.job-runs-on }}
193194
build-slice: ${{ matrix.job-runs-on }}
@@ -233,7 +234,7 @@ jobs:
233234

234235
- name: TestProjects
235236
id: TestProjects
236-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} TestProjects --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- TestProjects --skip --headless' }}
237+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom TestProjects --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- TestProjects --skip --headless' }}
237238
env:
238239
job-runs-on: ${{ matrix.job-runs-on }}
239240
test-framework: ${{ matrix.test-framework }}
@@ -377,7 +378,7 @@ jobs:
377378

378379
- name: PushToNuget
379380
id: PushToNuget
380-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} PushToNuget --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- PushToNuget --skip --headless' }}
381+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom PushToNuget --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- PushToNuget --skip --headless' }}
381382
env:
382383
build-id: ${{ needs.SetupBuildInfo.outputs.build-id }}
383384
azure-vault-app-secret: ${{ secrets.AZURE_VAULT_APP_SECRET }}
@@ -1138,7 +1139,7 @@ jobs:
11381139

11391140
- name: PushToRelease
11401141
id: PushToRelease
1141-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} PushToRelease --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- PushToRelease --skip --headless' }}
1142+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom PushToRelease --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- PushToRelease --skip --headless' }}
11421143
env:
11431144
build-version: ${{ needs.SetupBuildInfo.outputs.build-version }}
11441145
azure-vault-app-secret: ${{ secrets.AZURE_VAULT_APP_SECRET }}

.github/workflows/Dependabot Enable auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
- name: ApproveDependabotPr
3838
id: ApproveDependabotPr
39-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} ApproveDependabotPr --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- ApproveDependabotPr --skip --headless' }}
39+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom ApproveDependabotPr --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- ApproveDependabotPr --skip --headless' }}
4040
env:
4141
azure-vault-app-secret: ${{ secrets.AZURE_VAULT_APP_SECRET }}
4242
azure-vault-address: ${{ vars.AZURE_VAULT_ADDRESS }}

.github/workflows/Validate.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: SetupBuildInfo
4343
id: SetupBuildInfo
44-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} SetupBuildInfo --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- SetupBuildInfo --skip --headless' }}
44+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom SetupBuildInfo --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- SetupBuildInfo --skip --headless' }}
4545
env:
4646
pull-request-number: ${{ github.event.number }}
4747

@@ -71,7 +71,7 @@ jobs:
7171

7272
- name: BuildAtom
7373
id: BuildAtom
74-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} BuildAtom --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- BuildAtom --skip --headless' }}
74+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom BuildAtom --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- BuildAtom --skip --headless' }}
7575
env:
7676
job-runs-on: ${{ matrix.job-runs-on }}
7777
build-slice: ${{ matrix.job-runs-on }}
@@ -112,7 +112,7 @@ jobs:
112112

113113
- name: PackProjects
114114
id: PackProjects
115-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} PackProjects --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- PackProjects --skip --headless' }}
115+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom PackProjects --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- PackProjects --skip --headless' }}
116116

117117
PackTool:
118118
strategy:
@@ -140,7 +140,7 @@ jobs:
140140

141141
- name: PackTool
142142
id: PackTool
143-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} PackTool --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- PackTool --skip --headless' }}
143+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom PackTool --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- PackTool --skip --headless' }}
144144
env:
145145
job-runs-on: ${{ matrix.job-runs-on }}
146146
build-slice: ${{ matrix.job-runs-on }}
@@ -180,7 +180,7 @@ jobs:
180180

181181
- name: TestProjects
182182
id: TestProjects
183-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} TestProjects --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- TestProjects --skip --headless' }}
183+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom TestProjects --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- TestProjects --skip --headless' }}
184184
env:
185185
job-runs-on: ${{ matrix.job-runs-on }}
186186
test-framework: ${{ matrix.test-framework }}
@@ -251,7 +251,7 @@ jobs:
251251

252252
- name: CheckPrForBreakingChanges
253253
id: CheckPrForBreakingChanges
254-
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && format('.atom/{0} CheckPrForBreakingChanges --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom') || 'dotnet run --project _atom/_atom.csproj -- CheckPrForBreakingChanges --skip --headless' }}
254+
run: ${{ steps.cache-restore-atom-build.outputs.cache-hit && '.atom/_atom CheckPrForBreakingChanges --skip --headless' || 'dotnet run --project _atom/_atom.csproj -- CheckPrForBreakingChanges --skip --headless' }}
255255
env:
256256
build-version: ${{ needs.SetupBuildInfo.outputs.build-version }}
257257
azure-vault-app-secret: ${{ secrets.AZURE_VAULT_APP_SECRET }}

DecSm.Atom.Module.GithubWorkflows/Generation/GithubWorkflowWriter.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,11 +747,16 @@ private void WriteCommandStep(
747747

748748
if (runTargetStepIf.Count > 0)
749749
{
750-
var condition = WorkflowExpressions.True.And(runTargetStepIf
751-
.Select(x => x.Condition)
752-
.ToArray());
753-
754-
WriteLine($"if: {condition}");
750+
var condition = runTargetStepIf.Count > 1
751+
? runTargetStepIf[0]
752+
.Condition
753+
.And(runTargetStepIf
754+
.Skip(1)
755+
.Select(x => x.Condition)
756+
.ToArray())
757+
: runTargetStepIf[0].Condition;
758+
759+
WriteLine($"if: {workflowExpressionGenerator.Write(condition)}");
755760
}
756761

757762
var customAtomCommand = workflow

DecSm.Atom/Experimental/Sandbox.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ namespace DecSm.Atom.Experimental;
33
[UnstableAPI]
44
public sealed record CustomAtomCommand : IWorkflowOption
55
{
6-
public string Write(
7-
WorkflowModel workflow,
8-
WorkflowStepModel workflowStep,
9-
IAtomFileSystem fileSystem)
6+
public string Write(WorkflowModel workflow, WorkflowStepModel workflowStep, IAtomFileSystem fileSystem)
107
{
118
var cacheHitCommand =
12-
$"format('.atom/{{0}} {workflowStep.Name} --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom')";
9+
// $"format('.atom/{{0}} {workflowStep.Name} --skip --headless', runner.os == 'windows' && '_atom.exe' || '_atom')";
10+
$"'.atom/_atom {workflowStep.Name} --skip --headless'";
1311

1412
string cacheMissCommand;
1513

_atom/Build.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ internal partial class Build : BuildDefinition,
137137
.BuildAtom
138138
.WithGithubRunsOnMatrix(PlatformNames)
139139
.WithOptions(new CleanAtomDirectory(),
140+
new RunTargetStepIf(WorkflowExpressions
141+
.Literal("steps.cache-restore-atom-build.outputs.cache-hit")
142+
.NotEqualTo(true)),
140143
WorkflowOptions.Cache.Save(AtomBuildCacheName, AtomBuildCacheKey, AtomBuildCachePaths)),
141144
WorkflowTargets.PackProjects,
142145
WorkflowTargets.PackTool.WithGithubRunsOnMatrix(PlatformNames),

_atom/Targets/IBuildTargets.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ await DotnetPackAndStage(FileSystem.GetPath<Projects.DecSm_Atom_Tool>(),
8787

8888
FileSystem.Directory.CreateDirectory(cachedDirectory);
8989

90-
FileSystem.File.Move(atomExecutablePath, cachedDirectory / atomExecutableName);
90+
foreach (var file in FileSystem.Directory.EnumerateFiles(
91+
FileSystem.AtomPublishDirectory / Projects._atom.Name,
92+
"*",
93+
SearchOption.TopDirectoryOnly))
94+
FileSystem.File.Move(file, cachedDirectory / FileSystem.Path.GetFileName(file));
9195
});
9296
}

0 commit comments

Comments
 (0)