Skip to content

Commit

Permalink
Add additional workflow to prevent race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
atharva-2001 committed Jan 27, 2025
1 parent eddc976 commit dfa4fde
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 16 deletions.
31 changes: 15 additions & 16 deletions .github/actions/setup_lfs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,30 @@ runs:
working-directory: tardis-regression-data
shell: bash

- name: Restore LFS cache
- name: Initial LFS cache restore attempt
uses: actions/cache/restore@v4
id: lfs-cache-regression-data
with:
path: tardis-regression-data/.git/lfs
key: tardis-regression-${{ inputs.atom-data-sparse == 'true' && 'atom-data-sparse' || 'full-data' }}-${{ hashFiles('tardis-regression-data/.lfs-files-list') }}-v1
key: tardis-regression-${{ inputs.atom-data-sparse == 'true' && 'atom-data-sparse' || 'full-data' }}-${{ hashFiles('tardis-regression-data/.lfs-files-list') }}-${{ inputs.regression-data-repo }}-v1

- name: Git LFS Pull
run: git lfs pull
working-directory: tardis-regression-data
- name: Download and cache LFS files if cache miss
uses: ./.github/workflows/lfs-cache.yml
if: steps.lfs-cache-regression-data.outputs.cache-hit != 'true'
shell: bash
with:
atom-data-sparse: ${{ inputs.atom-data-sparse }}
regression-data-repo: ${{ inputs.regression-data-repo }}
lfs-files-list: tardis-regression-data/.lfs-files-list

- name: Restore newly created LFS cache
uses: actions/cache/restore@v4
id: lfs-cache-regression-data-final
with:
path: tardis-regression-data/.git/lfs
key: tardis-regression-${{ inputs.atom-data-sparse == 'true' && 'atom-data-sparse' || 'full-data' }}-${{ hashFiles('tardis-regression-data/.lfs-files-list') }}-${{ inputs.regression-data-repo }}-v1

- name: Git LFS Checkout
run: git lfs checkout
working-directory: tardis-regression-data
if: steps.lfs-cache-regression-data.outputs.cache-hit == 'true'
shell: bash

- name: Save LFS cache if not found
# uses fake ternary
# for reference: https://github.com/orgs/community/discussions/26738#discussioncomment-3253176
if: ${{ steps.lfs-cache-regression-data.outputs.cache-hit != 'true' && !contains(github.ref, 'merge') && always() || false }}
uses: actions/cache/save@v4
id: lfs-cache-regression-data-save
with:
path: tardis-regression-data/.git/lfs
key: tardis-regression-${{ inputs.atom-data-sparse == 'true' && 'atom-data-sparse' || 'full-data' }}-${{ hashFiles('tardis-regression-data/.lfs-files-list') }}-v1
71 changes: 71 additions & 0 deletions .github/workflows/lfs-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Save LFS Cache

on:
workflow_dispatch:
workflow_call:
inputs:
atom-data-sparse:
description: "Only download atom data files"
required: false
default: false
type: boolean
regression-data-repo:
description: "tardis regression data repository"
required: false
default: "tardis-sn/tardis-regression-data"
type: string
lfs-files-list:
description: "LFS files list"
required: false
type: string

defaults:
run:
shell: bash -l {0}

concurrency:
# Only one workflow can run at a time
# the workflow group is a unique identifier and contains the workflow name, pull request number, atom data sparse, and regression data repo
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ inputs.atom-data-sparse == 'true' && 'atom-data-sparse' || 'full-data' }}-${{ inputs.regression-data-repo }}
cancel-in-progress: true


jobs:
lfs-cache:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ inputs.regression-data-repo }}
path: tardis-regression-data
sparse-checkout: ${{ inputs.atom-data-sparse == 'true' && 'atom_data/kurucz_cd23_chianti_H_He.h5' || '' }}

- name: Print files
run: |
echo ${{ inputs.lfs-files-list }}
echo ${{ inputs.atom-data-sparse }}
echo ${{ inputs.regression-data-repo }}
- name: Git LFS Pull Atom Data
run: git lfs pull --include-ref=atom_data/kurucz_cd23_chianti_H_He.h5
if: ${{ inputs.atom-data-sparse == 'true' }}
working-directory: tardis-regression-data
shell: bash

- name: Git LFS Pull Full Data
run: git lfs pull
if: ${{ inputs.atom-data-sparse == 'false' }}
working-directory: tardis-regression-data
shell: bash

- name: Git LFS Checkout
run: git lfs checkout
working-directory: tardis-regression-data
shell: bash

- name: Save LFS cache if not found
uses: actions/cache/save@v4
with:
path: tardis-regression-data/.git/lfs
key: tardis-regression-${{ inputs.atom-data-sparse == 'true' && 'atom-data-sparse' || 'full-data' }}-${{ hashFiles('tardis-regression-data/.lfs-files-list') }}-${{ inputs.regression-data-repo }}-v1

0 comments on commit dfa4fde

Please # to comment.