Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Jan 31, 2025
1 parent 59b98bd commit 3176242
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 155 deletions.
39 changes: 27 additions & 12 deletions .github/actions/decision/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: Decision
description: Decision
outputs:
data:
description: Decision data
value: ${{ steps.filtered.outputs.result }}
matrix:
description: Decision matrix
value: ${{ steps.matrix.outputs.result }}
artifacts:
description: Artifacts data
value: ${{ steps.decision.outputs.artifacts }}
mounts:
description: Mounts data
value: ${{ steps.decision.outputs.mounts }}
runs:
using: "composite"
steps:
Expand All @@ -13,27 +19,36 @@ runs:
run: |
python3 CI/decision.py >> $GITHUB_OUTPUT
- uses: actions/setup-node@v3
if: ${{ steps.decision.outputs.data }}
if: ${{ steps.decision.outputs.matrix }}
with:
node-version: '20.x'
- shell: bash
if: ${{ steps.decision.outputs.data }}
if: ${{ steps.decision.outputs.matrix }}
run: npm install @actions/cache
- name: Check dependencies
id: filtered
if: ${{ steps.decision.outputs.data }}
id: matrix
if: ${{ steps.decision.outputs.matrix }}
uses: actions/github-script@v7
with:
script: |
const cache = require('@actions/cache');
const data = ${{ toJSON(fromJSON(steps.decision.outputs.data)) }};
const matrix = ${{ toJSON(fromJSON(steps.decision.outputs.matrix)) }};
const artifacts = ${{ toJSON(fromJSON(steps.decision.outputs.artifacts)) }};
const filtered = await Promise.all(
Object.entries(data).map(async ([name, items]) => {
Object.entries(matrix).map(async ([name, items]) => {
const filtered_items = [];
for (const item of items) {
if (!('key' in item) || !await cache.restoreCache(item.paths, item.key, [], { lookupOnly: true }, true)) {
const { key, paths, ...filtered_item } = item;
filtered_items.push(filtered_item);
if (item.task in artifacts) {
}
try {
if (!(item.task in artifacts) || !await cache.restoreCache(artifacts[item.task].paths, artifacts[item.task].key, [], { lookupOnly: true }, true)) {
filtered_items.push(item);
}} catch (e) { console.log(item.task);
console.log(item.task in artifacts);
console.log(JSON.stringify(artifacts[item.task]));
console.log(JSON.stringify(artifacts[item.task].paths));
console.log(JSON.stringify(artifacts[item.task].key));
throw e;
}
}
return [name, filtered_items];
Expand Down
19 changes: 7 additions & 12 deletions .github/actions/mounts/action.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
name: Mount dependencies
description: Mount dependencies
inputs:
name:
description: task name
mounts:
description: mounts
required: true
runs:
using: "composite"
steps:
- name: Compute dependencies
id: dependencies
shell: bash
run: |
python3 CI/info.py --mounts "${{ inputs.name }}" >> $GITHUB_OUTPUT
- uses: actions/setup-node@v3
if: ${{ steps.dependencies.outputs.data }}
if: ${{ inputs.mounts }}
with:
node-version: '20.x'
- shell: bash
if: ${{ steps.dependencies.outputs.data }}
if: ${{ inputs.mounts }}
run: npm install @actions/cache
- name: Mount dependencies
if: ${{ steps.dependencies.outputs.data }}
if: ${{ inputs.mounts }}
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const cache = require('@actions/cache');
const data = ${{ toJSON(fromJSON(steps.dependencies.outputs.data)) }};
const mounts = ${{ toJSON(fromJSON(inputs.mounts)) }};
const pwd = process.cwd();
// Make actions/cache's getWorkingDirectory() return process.cwd.
delete process.env.GITHUB_WORKSPACE;
for (const mount of data) {
for (const mount of mounts) {
const dir = path.join(pwd, 'cache', mount.key, path.dirname(mount.artifact));
fs.mkdirSync(dir, { recursive: true });
process.chdir(dir);
Expand Down
28 changes: 11 additions & 17 deletions .github/actions/task/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ inputs:
name:
description: task name
required: true
mounts:
description: mounts for the task
required: false
artifacts:
description: artifacts from the task
required: false
runs:
using: "composite"
steps:
Expand All @@ -16,31 +22,19 @@ runs:
shell: bash
run: |
python3 -m pip install pip==20.3.4 wheel==0.37.0 --upgrade
- name: Artifact
id: artifacts
shell: bash
run: |
python3 CI/info.py --artifacts "${{ inputs.name }}" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
if: ${{ steps.artifacts.outputs.key }}
if: ${{ inputs.artifacts }}
id: cache
with:
path: ${{ join(fromJSON(steps.artifacts.outputs.path), '\n') }}
key: ${{ steps.artifacts.outputs.key }}
path: ${{ join(fromJSON(inputs.artifacts).paths, '\n') }}
key: ${{ fromJSON(input.artifacts).key }}
enableCrossOsArchive: true
- uses: ./.github/actions/mounts
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
if: ${{ steps.cache.outputs.cache-hit != 'true' && inputs.mounts }}
with:
name: ${{ inputs.name }}
mounts: ${{ inputs.mounts }}
- name: ${{ inputs.name }}
shell: bash
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: |
python3 CI/run.py --cache cache --no-recurse --out . "${{ inputs.name }}"
- uses: actions/upload-artifact@v4
if: ${{ !steps.artifacts.outputs.key && steps.artifacts.outputs.path }}
with:
name: ${{ steps.artifacts.outputs.taskId }}
path: ${{ join(fromJSON(steps.artifacts.outputs.path), '\n') }}
compression-level: 9
retention-days: 1
Loading

0 comments on commit 3176242

Please sign in to comment.