Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Jan 26, 2025
1 parent a622b4f commit 863c19f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/actions/mounts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ runs:
const cache = require('@actions/cache');
const data = ${{ toJSON(fromJSON(steps.dependencies.outputs.data)) }};
// Make actions/cache's getWorkingDirectory() return process.cwd.
delete process.env.GITHUB_GITHUB_WORKSPACE;
delete process.env.GITHUB_WORKSPACE;
for (const mount of data) {
const dir = path.join('cache', mount.key, path.dirname(mount.artifact));
fs.mkdirSync(dir, { recursive: true });
Expand Down
63 changes: 9 additions & 54 deletions .github/actions/task/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ inputs:
name:
description: task name
required: true
output:
description: pattern of output files
required: true
image:
description: docker image
dep1_name:
description: name of the first dependency
dep1_artifact:
description: name of the artifact from the first dependency
runs:
using: "composite"
steps:
Expand All @@ -25,59 +16,23 @@ runs:
shell: bash
run: |
python3 -m pip install pip==20.3.4 wheel==0.37.0 --upgrade
- uses: ./.github/actions/mounts
with:
name: ${{ inputs.name }}
- name: Docker image key
if: ${{ inputs.image }}
id: image-key
- name: Artifact
id: artifact
shell: bash
run: |
echo key=$(python3 CI/run.py --route "docker image: ${{ inputs.image }}") >> $GITHUB_OUTPUT
- name: Dependency key
if: ${{ inputs.dep1_name }}
id: dep1-key
shell: bash
run: |
echo key=$(python3 CI/run.py --route "${{ inputs.dep1_name }}") >> $GITHUB_OUTPUT
- name: Artifact key
id: artifact-key
shell: bash
run: |
echo key=$(python3 CI/run.py --route "${{ inputs.name }}") >> $GITHUB_OUTPUT
python3 CI/run.py --artifacts "${{ inputs.name }}" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
id: cache
with:
path: ${{ inputs.output }}
key: ${{ steps.artifact-key.outputs.key }}
path: ${{ fromJSON(steps.artifact.outputs.path) }}
key: ${{ steps.artifact.outputs.key }}
enableCrossOsArchive: true
- uses: actions/cache/restore@v4
if: ${{ inputs.image && steps.cache.outputs.cache-hit != 'true' }}
with:
path: dockerImage.tar.zst
key: ${{ steps.image-key.outputs.key }}
fail-on-cache-miss: true
- uses: actions/cache/restore@v4
if: ${{ inputs.dep1_name && steps.cache.outputs.cache-hit != 'true' }}
- uses: ./.github/actions/mounts
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
with:
path: ${{ inputs.dep1_artifact }}
key: ${{ steps.dep1-key.outputs.key }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: Prepare podman cache
if: ${{ inputs.image && steps.cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
mkdir -p "cache/${{ steps.image-key.outputs.key }}/public"
mv dockerImage.tar.zst "cache/${{ steps.image-key.outputs.key }}/public"
- name: Prepare dependency cache
if: ${{ inputs.dep1_name && steps.cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
mkdir -p "cache/${{ steps.dep1-key.outputs.key }}/public"
mv ${{ inputs.dep1_artifact }} "cache/${{ steps.dep1-key.outputs.key }}/public"
name: ${{ inputs.name }}
- name: ${{ inputs.name }}
shell: bash
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: |
python3 CI/run.py --cache cache --out . "${{ inputs.name }}"
python3 CI/run.py --cache cache --no-recurse --out . "${{ inputs.name }}"
17 changes: 0 additions & 17 deletions .github/workflows/env-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
- uses: ./.github/actions/task
with:
name: "docker image: base"
output: dockerImage.tar.zst

docker:
needs: docker-base
Expand All @@ -30,8 +29,6 @@ jobs:
- uses: ./.github/actions/task
with:
name: "docker image: ${{ matrix.image }}"
output: dockerImage.tar.zst
image: base

msys-base:
runs-on: ubuntu-latest
Expand All @@ -41,8 +38,6 @@ jobs:
- uses: ./.github/actions/task
with:
name: "msys2 image: base x86_64"
output: msys2.tar.zst
image: base

msys:
strategy:
Expand All @@ -58,9 +53,6 @@ jobs:
- uses: ./.github/actions/task
with:
name: "msys2 image: ${{ matrix.image }} x86_64"
output: msys2.tar.zst
dep1_name: "msys2 image: base x86_64"
dep1_artifact: msys2.tar.zst

git:
strategy:
Expand All @@ -78,15 +70,12 @@ jobs:
- uses: ./.github/actions/task
with:
name: git v${{ matrix.version }}
output: git-*.tar.zst
image: build-tools

mercurial:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
image: [build-tools]
version:
- 1.9.3
- 2.5.4
Expand All @@ -95,8 +84,6 @@ jobs:
include:
- os: windows-latest
version: 6.8 windows x86_64
dep1_name: "msys2 image: build x86_64"
dep1_artifact: msys2.tar.zst
- os: macos-13
version: 6.8 macos x86_64
- os: macos-14
Expand All @@ -109,7 +96,3 @@ jobs:
- uses: ./.github/actions/task
with:
name: hg v${{ matrix.version }}
output: mercurial-*.whl
image: ${{ matrix.image }}
dep1_name: ${{ matrix.dep1_name }}
dep1_artifact: ${{ matrix.dep1_artifact }}
29 changes: 25 additions & 4 deletions CI/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def link_or_copy(src, dest):
raise


def run_task(task, cwd, out=None, cache=None):
def run_task(task, cwd, out=None, cache=None, recurse=True):
id = task.id
task = task.task
payload = task.get("payload", {})
Expand All @@ -45,7 +45,10 @@ def run_task(task, cwd, out=None, cache=None):
artifacts_base_dir = os.path.join(cwd, task_id)
artifact = os.path.join(artifacts_base_dir, content["artifact"])
if not os.path.exists(artifact):
run_task(dep_task, cwd, cache=cache)
if recurse:
run_task(dep_task, cwd, cache=cache)
else:
raise RuntimeError("Missing dependency")

if directory := mount.get("directory"):
assert "file" not in mount
Expand Down Expand Up @@ -100,16 +103,28 @@ def main():
parser.add_argument("--cache", type=str, metavar="PATH")
parser.add_argument("--out", type=str, metavar="PATH")
parser.add_argument("--route", action="store_true")
parser.add_argument("--artifacts", action="store_true")
parser.add_argument("--mounts", action="store_true")
parser.add_argument("--no-recurse", action="store_true")
parser.add_argument("task")
args = parser.parse_args()
action.by_name["decision"].func()

if args.route or args.mounts:
if args.route or args.artifacts or args.mounts:
for t in Task.by_id.values():
if t.task.get("metadata", {}).get("name") == args.task:
if args.route:
print(t.task.get("routes")[0])
elif args.artifacts:
task = t.task
payload = task.get("payload", {})
paths = [
os.path.basename(artifact["name"])
for artifact in payload.get("artifacts", [])
]
print(f'key={task.get("routes")[0]}"')
paths = json.dumps(paths).replace('"', '\\"')
print(f"path={paths}")
elif args.mounts:

def info(mount):
Expand All @@ -130,7 +145,13 @@ def info(mount):
with tempfile.TemporaryDirectory(prefix="run_task") as tmpdir:
for t in Task.by_id.values():
if t.task.get("metadata", {}).get("name") == args.task:
run_task(t, cwd=tmpdir, out=args.out, cache=args.cache)
run_task(
t,
cwd=tmpdir,
out=args.out,
cache=args.cache,
recurse=not args.no_recurse,
)
break


Expand Down

0 comments on commit 863c19f

Please sign in to comment.