Save LFS Cache #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Save LFS Cache | |
on: | |
workflow_dispatch: | |
inputs: | |
atom-data-sparse: | |
description: "If true, only downloads atom_data/kurucz_cd23_chianti_H_He.h5" | |
required: false | |
default: false | |
type: boolean | |
regression-data-repo: | |
description: "Repository containing regression data (format: owner/repo)" | |
required: false | |
default: "tardis-sn/tardis-regression-data" | |
type: string | |
allow_lfs_pull: | |
description: "If true, allows LFS pull operations" | |
required: false | |
default: false | |
type: boolean | |
workflow_call: | |
inputs: | |
atom-data-sparse: | |
description: "If true, only downloads atom_data/kurucz_cd23_chianti_H_He.h5" | |
required: false | |
default: false | |
type: boolean | |
regression-data-repo: | |
description: "Repository containing regression data (format: owner/repo)" | |
required: false | |
default: "tardis-sn/tardis-regression-data" | |
type: string | |
allow_lfs_pull: | |
description: "If true, allows LFS pull operations" | |
required: false | |
default: false | |
type: boolean | |
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: | |
if: github.repository_owner == 'tardis-sn' | |
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: Create LFS file list | |
run: | | |
if [ "${{ inputs.atom-data-sparse }}" == "true" ]; then | |
echo "Using atom data sparse checkout" | |
echo "atom_data/kurucz_cd23_chianti_H_He.h5" > .lfs-files-list | |
else | |
echo "Using full repository checkout" | |
git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-files-list | |
fi | |
working-directory: tardis-regression-data | |
- name: Test cache availability | |
uses: actions/cache/restore@v4 | |
id: test-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') }}-${{ inputs.regression-data-repo }}-v1 | |
lookup-only: true | |
- name: Fail if LFS pull is needed but not allowed | |
if: | | |
steps.test-lfs-cache-regression-data.outputs.cache-hit != 'true' && | |
inputs.allow_lfs_pull != true | |
run: | | |
echo "Error: LFS pull is required but not allowed (allow_lfs_pull is false)" | |
exit 1 | |
- name: Git LFS Pull Atom Data | |
if: | | |
inputs.atom-data-sparse == true && | |
steps.test-lfs-cache-regression-data.outputs.cache-hit != 'true' && | |
inputs.allow_lfs_pull == true | |
run: git lfs pull --include=atom_data/kurucz_cd23_chianti_H_He.h5 | |
working-directory: tardis-regression-data | |
- name: Git LFS Pull Full Data | |
if: | | |
inputs.atom-data-sparse == false && | |
steps.test-lfs-cache-regression-data.outputs.cache-hit != 'true' && | |
inputs.allow_lfs_pull == true | |
run: git lfs pull | |
working-directory: tardis-regression-data | |
- name: Git LFS Checkout | |
if: ${{ inputs.atom-data-sparse == true }} | |
run: git lfs checkout atom_data/kurucz_cd23_chianti_H_He.h5 | |
working-directory: tardis-regression-data | |
- name: Git LFS Checkout Full | |
if: ${{ inputs.atom-data-sparse == false }} | |
run: git lfs checkout | |
working-directory: tardis-regression-data | |
- name: Save LFS cache if not found | |
uses: actions/cache/save@v4 | |
if: ${{ steps.test-lfs-cache-regression-data.outputs.cache-hit != 'true' && !contains(github.ref, 'merge') }} | |
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 |