Skip to content

Commit

Permalink
Ensure incompatible artifact actions aren't synced to GHES
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmgross committed Jan 17, 2025
1 parent 890c78b commit 72cd01c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/sync-ghes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ jobs:
node-version: '20'
cache: 'npm'
cache-dependency-path: script/sync-ghes/package-lock.json

# # The V4 Artifact actions are not yet supported on GHES
# # This step ensure any compatible workflows continue to work on GHES
# - run: |
# find . -type f \( -name '*.yaml' -o -name '*.yml' \) ! -path './.github/workflows/*' -exec sed -i '' 's/actions\/upload-artifact@v4/actions\/upload-artifact@v3/g' {} \;
# find . -type f \( -name '*.yaml' -o -name '*.yml' \) ! -path './.github/workflows/*' -exec sed -i '' 's/actions\/download-artifact@v4/actions\/download-artifact@v3/g' {} \;

- name: Check starter workflows for GHES compat
run: |
npm ci
Expand Down
21 changes: 21 additions & 0 deletions script/sync-ghes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ async function checkWorkflow(
})
),
]);

// The v4 versions of upload and download artifact are not yet supported on GHES
console.group("Updating all compatible workflows to use v3 of the artifact actions");
for (const workflow of result.compatibleWorkflows) {
const path = join(workflow.folder, `${workflow.id}.yml`);
console.log(`Updating ${path}`);
const contents = await fs.readFile(path, "utf8");

if (contents.includes("actions/upload-artifact@v4") || contents.includes("actions/download-artifact@v4")) {
console.log("Found v4 artifact actions, updating to v3");
} else {
continue;
}

let updatedContents = contents.replace(/actions\/upload-artifact@v4/g, "actions/upload-artifact@v3");
updatedContents = updatedContents.replace(/actions\/download-artifact@v4/g, "actions/download-artifact@v3");

await fs.writeFile(path, updatedContents);
}
console.groupEnd();

} catch (e) {
console.error("Unhandled error while syncing workflows", e);
process.exitCode = 1;
Expand Down

0 comments on commit 72cd01c

Please sign in to comment.