Skip to content

Commit bebefa4

Browse files
committed
tweak: stop GitHub from wrapping generated ZIP artifacts in another ZIP
1 parent 3706e64 commit bebefa4

File tree

11 files changed

+34
-27
lines changed

11 files changed

+34
-27
lines changed

.github/workflows/test_all_inputs_override.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
packsquash_version: latest
2424
system_id: c5eb0603-093c-41fd-9c21-88c34a429e3b # <- (Automatically generated)
25-
artifact_name: Test Artifact Name # <- Optimized pack
25+
artifact_name: Test Artifact Name.zip # <- Optimized pack.zip
2626
show_emoji_in_packsquash_logs: false # <- true
2727
enable_color_in_packsquash_logs: false # <- true
2828
token: ${{ secrets.GITHUB_TOKEN }} # <- ${{ github.token }}

.github/workflows/test_run_in_multiple_steps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ jobs:
2121
uses: ./ # Uses an action in the root directory
2222
with:
2323
packsquash_version: latest
24-
artifact_name: 'Optimized pack 1'
24+
artifact_name: Optimized pack 1.zip
2525
options: |
2626
pack_directory = 'test/empty_resource_pack'
2727
- name: Run PackSquash
2828
uses: ./
2929
with:
3030
packsquash_version: latest
31-
artifact_name: 'Optimized pack 2'
31+
artifact_name: Optimized pack 2.zip
3232
options: |
3333
pack_directory = 'test/empty_resource_pack'

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11-
No changes yet.
11+
### Changed
12+
13+
- Uploaded pack file ZIP artifacts are no longer wrapped in an additional ZIP file by GitHub. This leverages a recently introduced feature for disabling that behavior added in a [pull request to `actions/toolkit`](https://github.com/actions/toolkit/pull/2256).
1214

1315
## [4.0.4] - 2026-01-01
1416

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ repositories.
370370

371371
**Default value**
372372

373-
`Optimized pack`
373+
`Optimized pack.zip`
374374

375375
**Description**
376376

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ inputs:
2424
artifact_name:
2525
description: 'The name of the workflow artifact containing the generated ZIP file that the action will upload. Later steps in the workflow will be able to download it by this name. Changing this may be needed in complex workflows, where the action runs several times.'
2626
required: false
27-
default: 'Optimized pack'
27+
default: 'Optimized pack.zip'
2828
show_emoji_in_packsquash_logs:
2929
description: 'If true, the action will instruct PackSquash to use emojis in the logs it generates, which look prettier. Otherwise, plain ASCII decoration characters will be used instead.'
3030
required: false

dist/cleanup_working_directory/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cache.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { context } from "@actions/github";
44
import { getInputValue } from "./action_input";
55
import type { PackSquashOptions } from "./packsquash_options";
66
import { getBranchName, md5Hash } from "./util";
7-
import { downloadLatestArtifact, getCurrentWorkflowId } from "./workflow";
7+
import { downloadLatestPackArtifact, getCurrentWorkflowId } from "./workflow";
88
import type WorkingDirectory from "./working_directory";
99

1010
export async function computeCacheKeys(packSquashOptions: PackSquashOptions) {
@@ -51,8 +51,7 @@ export async function restorePackSquashCache(
5151
throw new Error("Could not get current workflow ID");
5252
}
5353

54-
await downloadLatestArtifact(
55-
workingDirectory,
54+
await downloadLatestPackArtifact(
5655
owner,
5756
repo,
5857
branch,

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import setPackFilesModificationTimesFromCommits from "./git_set_file_times";
66
import { printPackSquashVersion, runPackSquash } from "./packsquash";
77
import { PackSquashOptions } from "./packsquash_options";
88
import { getEnvOrThrow } from "./util";
9-
import { uploadArtifact } from "./workflow";
9+
import { uploadPackArtifact } from "./workflow";
1010
import WorkingDirectory from "./working_directory";
1111

1212
async function run() {
@@ -41,7 +41,7 @@ async function run() {
4141

4242
await runPackSquash(packSquashOptions, binaryEnvironment, workingDirectory);
4343

44-
await uploadArtifact(packSquashOptions);
44+
await uploadPackArtifact(workingDirectory, packSquashOptions);
4545

4646
if (packSquashOptions.mayCacheBeUsed() && !cacheRestored) {
4747
await savePackSquashCache(workingDirectory, key);

src/workflow.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createWriteStream } from "node:fs";
2+
import { copyFile } from "node:fs/promises";
13
import { dirname } from "node:path";
24
import { pipeline } from "node:stream/promises";
35
import { default as artifactClient } from "@actions/artifact";
@@ -6,7 +8,6 @@ import { HttpClient } from "@actions/http-client";
68
import { getInputValue } from "./action_input";
79
import octokit from "./octokit";
810
import type { PackSquashOptions } from "./packsquash_options";
9-
import { extractFirstFileFromZip } from "./util";
1011
import type WorkingDirectory from "./working_directory";
1112

1213
export async function getCurrentWorkflowId(owner: string, repo: string, workflow: string) {
@@ -17,28 +18,30 @@ export async function getCurrentWorkflowId(owner: string, repo: string, workflow
1718
return workflows.data.workflows.find(w => w.name === workflow)?.id;
1819
}
1920

20-
export async function uploadArtifact(packSquashOptions: PackSquashOptions) {
21+
export async function uploadPackArtifact(workingDirectory: WorkingDirectory, packSquashOptions: PackSquashOptions) {
2122
if ("ACT" in process.env) {
2223
debug("Local act test environment detected. Skipping artifact upload");
2324
return;
2425
}
2526

2627
startGroup("Upload generated ZIP file as artifact");
28+
const artifactName = getInputValue("artifact_name");
2729
const outputFilePath = packSquashOptions.getOutputFilePath();
28-
const response = await artifactClient.uploadArtifact(
29-
getInputValue("artifact_name"),
30-
[outputFilePath],
31-
dirname(outputFilePath),
32-
);
30+
const artifactFilePath = workingDirectory.temporaryFile("pack_artifact_upload", artifactName);
31+
32+
await copyFile(outputFilePath, artifactFilePath);
33+
34+
const response = await artifactClient.uploadArtifact(artifactName, [artifactFilePath], dirname(artifactFilePath), {
35+
skipArchive: true,
36+
});
3337
endGroup();
3438

35-
if (!response.size) {
39+
if (!response?.size) {
3640
throw new Error("Artifact upload failed");
3741
}
3842
}
3943

40-
export async function downloadLatestArtifact(
41-
workingDirectory: WorkingDirectory,
44+
export async function downloadLatestPackArtifact(
4245
owner: string,
4346
repo: string,
4447
branch: string,
@@ -85,13 +88,12 @@ export async function downloadLatestArtifact(
8588
artifact_id: artifact.id,
8689
});
8790

88-
debug(`Extracting ${artifactName} artifact archive (#${latestRun.run_number})`);
91+
debug(`Downloading ${artifactName} artifact (#${latestRun.run_number})`);
8992
try {
90-
await pipeline((await new HttpClient().get(zip.url)).message, workingDirectory.temporaryDownloadFileWriteStream);
93+
await pipeline((await new HttpClient().get(zip.url)).message, createWriteStream(destinationPath));
9194
} catch {
9295
throw new Error(`Could not download the latest ${artifactName} artifact`);
9396
}
94-
await extractFirstFileFromZip(workingDirectory.temporaryDownloadFile, destinationPath);
9597

9698
info(`Successfully downloaded the latest ${artifactName} artifact`);
9799
}

0 commit comments

Comments
 (0)