From 5d22754e705b98fd96fb22b4f995fb55bba59bce Mon Sep 17 00:00:00 2001 From: Atharva Arya <55894364+atharva-2001@users.noreply.github.com> Date: Fri, 12 Jul 2024 18:37:59 +0530 Subject: [PATCH] Move setup environment steps to composite action (#2698) * Test moving setup environment steps to composite action file * Replace steps with action in other docs pre release and update refdata --- .github/actions/setup_env/action.yml | 32 ++++++++++++++++++++++++++++ .github/workflows/build-docs.yml | 20 +++++------------ .github/workflows/pre-release.yml | 21 ++++-------------- .github/workflows/tests.yml | 22 ++++--------------- .github/workflows/update-refdata.yml | 21 ++++-------------- 5 files changed, 49 insertions(+), 67 deletions(-) create mode 100644 .github/actions/setup_env/action.yml diff --git a/.github/actions/setup_env/action.yml b/.github/actions/setup_env/action.yml new file mode 100644 index 00000000000..8c64f24dff4 --- /dev/null +++ b/.github/actions/setup_env/action.yml @@ -0,0 +1,32 @@ +name: "Setup environment" +description: "Sets up environment for tardis and caches it" + +inputs: + os-label: + description: "os label for lock file, default linux" + required: true + default: "linux" + +runs: + using: "composite" + steps: + - name: Download Lock File + run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-${{ inputs.os-label }}.lock + if: matrix.pip == true + shell: bash + + - name: Generate Cache Key + run: | + file_hash=$(cat conda-${{ inputs.os-label }}.lock | shasum -a 256 | cut -d' ' -f1) + echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}" + id: cache-environment-key + shell: bash + + - uses: mamba-org/setup-micromamba@v1 + with: + environment-file: conda-${{ inputs.os-label }}.lock + cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }} + cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }} + environment-name: tardis + cache-environment: true + cache-downloads: true diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 7fc44e742e2..1e5f1ed9a77 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -88,28 +88,18 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} if: github.event_name == 'pull_request_target' - - name: Generate Cache Key - run: | - file_hash=$(cat conda-linux-64.lock | shasum -a 256 | cut -d' ' -f1) - echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}" - id: cache-environment-key - - name: Setup LFS uses: ./.github/actions/setup_lfs + + - name: Setup environment + uses: ./.github/actions/setup_env + with: + os-label: linux-64 - name: Copy atom_data run: | mkdir -p ~/Downloads/tardis-data && cp -a ./tardis-refdata/atom_data/. ~/Downloads/tardis-data - - uses: mamba-org/setup-micromamba@v1 - with: - environment-file: conda-linux-64.lock - cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }} - cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }} - environment-name: tardis - cache-environment: true - cache-downloads: true - - name: Install package run: pip install -e . diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 69268254ed0..4c3496b428b 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -27,23 +27,10 @@ jobs: env: KEY_SECRET_JSON: ${{ secrets.ZENODO_KEY_SECRET_JSON }} - - name: Download Lock File - run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-linux-64.lock - - - name: Generate Cache Key - run: | - file_hash=$(cat conda-linux-64.lock | shasum -a 256 | cut -d' ' -f1) - echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}" - id: cache-environment-key - - - uses: mamba-org/setup-micromamba@v1 - with: - environment-file: conda-linux-64.lock - cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }} - cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }} - environment-name: tardis - cache-environment: true - cache-downloads: true + - name: Setup environment + uses: ./.github/actions/setup_env + with: + os-label: linux-64 - name: Run Notebook run: jupyter nbconvert gather_data.ipynb --to html --execute --ExecutePreprocessor.timeout=6000 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 640b5f75652..dab7e450cdf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,25 +56,11 @@ jobs: - name: Setup LFS uses: ./.github/actions/setup_lfs - - - name: Download Lock File - run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-${{ matrix.label }}.lock - if: matrix.pip == true - - name: Generate Cache Key - run: | - file_hash=$(cat conda-${{ matrix.label }}.lock | shasum -a 256 | cut -d' ' -f1) - echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}" - id: cache-environment-key - - - uses: mamba-org/setup-micromamba@v1 - with: - environment-file: conda-${{ matrix.label }}.lock - cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }} - cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }} - environment-name: tardis - cache-environment: true - cache-downloads: true + - name: Setup environment + uses: ./.github/actions/setup_env + with: + os-label: ${{ matrix.label }} - name: Install package editable run: | diff --git a/.github/workflows/update-refdata.yml b/.github/workflows/update-refdata.yml index 467c2c300e6..6b9f1485c94 100644 --- a/.github/workflows/update-refdata.yml +++ b/.github/workflows/update-refdata.yml @@ -32,23 +32,10 @@ jobs: - name: Setup LFS uses: ./.github/actions/setup_lfs - - name: Download Lock File - run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-linux-64.lock - - - name: Generate Cache Key - run: | - file_hash=$(cat conda-linux-64.lock | shasum -a 256 | cut -d' ' -f1) - echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}" - id: cache-environment-key - - - uses: mamba-org/setup-micromamba@v1 - with: - environment-file: conda-linux-64.lock - cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }} - cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }} - environment-name: tardis - cache-environment: true - cache-downloads: true + - name: Setup environment + uses: ./.github/actions/setup_env + with: + os-label: linux-64 - name: Install package run: pip install -e .