From dff3152f248171296c96ff2caf41f7b38a731ba2 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 3 Oct 2023 15:57:08 -0400 Subject: [PATCH] attempt at reusable workflow --- .github/workflows/roman_ci.yml | 47 +----------------- .github/workflows/webbpsf_data.yml | 80 ++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 61 deletions(-) diff --git a/.github/workflows/roman_ci.yml b/.github/workflows/roman_ci.yml index 371e148c8..399748cc0 100644 --- a/.github/workflows/roman_ci.yml +++ b/.github/workflows/roman_ci.yml @@ -21,52 +21,7 @@ concurrency: jobs: data: - name: retrieve current CRDS context, and WebbPSF data - runs-on: ubuntu-latest - env: - OBSERVATORY: roman - CRDS_SERVER_URL: https://roman-crds.stsci.edu - # CRDS_PATH here should match DATA_PATH in webbpsf_data.yml - CRDS_PATH: /tmp/data - GH_TOKEN: ${{ github.token }} - outputs: - # TODO simplify data_path and crds_path as they are the same - data_path: ${{ steps.data.outputs.path }} - webbpsf_path: ${{ steps.webbpsf_path.outputs.path }} - data_hash: ${{ steps.data_hash.outputs.hash }} - crds_path: ${{ steps.crds_path.outputs.path }} - crds_context: ${{ steps.crds_context.outputs.pmap }} - crds_server: ${{ steps.crds_server.outputs.url }} - steps: - # crds: - - id: data - run: echo "path=/tmp/data" >> $GITHUB_OUTPUT - - id: crds_context - run: > - echo "pmap=$( - curl -s -X POST -d '{"jsonrpc": "1.0", "method": "get_default_context", "params": ["${{ env.OBSERVATORY }}"], "id": 1}' ${{ env.CRDS_SERVER_URL }}/json/ | - python -c "import sys, json; print(json.load(sys.stdin)['result'])" - )" >> $GITHUB_OUTPUT - # Get default CRDS_CONTEXT without installing crds client - # See https://hst-crds.stsci.edu/static/users_guide/web_services.html#generic-request - - id: crds_path - run: echo "path=${{ env.CRDS_PATH }}" >> $GITHUB_OUTPUT - - id: crds_server - run: echo "url=${{ env.CRDS_SERVER_URL }}" >> $GITHUB_OUTPUT - # webbpsf: - - id: data_hash - run: | - # use actions/gh-actions-cache to allow filtering by key - gh extension install actions/gh-actions-cache - - RECENT=$(gh actions-cache list -R spacetelescope/romancal --key webbpsf- --sort created-at | cut -f 1 | head -n 1) - echo "RECENT=$RECENT" - HASH=$(echo $RECENT | cut -d '-' -f 2) - echo "HASH=$HASH" - echo "hash=$HASH" >> $GITHUB_OUTPUT - if [ "$HASH" == '' ]; then exit 1; fi - - id: webbpsf_path - run: echo "path=${{ steps.data.outputs.path }}/webbpsf-data" >> $GITHUB_OUTPUT + uses: ./.github/workflows/webbpsf_data.yml check: uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1 with: diff --git a/.github/workflows/webbpsf_data.yml b/.github/workflows/webbpsf_data.yml index 06b102388..f6ff5c8e2 100644 --- a/.github/workflows/webbpsf_data.yml +++ b/.github/workflows/webbpsf_data.yml @@ -1,26 +1,25 @@ name: check/update webbpsf cache on: + workflow_call: + outputs: + webbpsf_path: + value: ${{ jobs.data.outputs.webbpsf_path }} + data_hash: + value: ${{ jobs.data.outputs.data_hash }} + crds_path: + value: ${{ jobs.data.outputs.crds_path }} + crds_context: + value: ${{ jobs.data.outputs.crds_context }} + crds_server: + value: ${{ jobs.data.outputs.crds_server }} + workflow_dispatch: schedule: - cron: "42 4 * * 3" - pull_request: - # We also want this workflow triggered if the `update webbpsf data` label is - # added or present when PR is updated - types: - - opened - - reopened - - labeled - - unlabeled - - synchronize - workflow_dispatch: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true jobs: webbpsf-data: - if: (github.repository == 'spacetelescope/romancal' && (github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'update webbpsf data'))) + if: (github.repository == 'spacetelescope/romancal' && (github.event_name == 'schedule' || github.event_name == 'workflow_call' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'update webbpsf data'))) name: fetch, check, and possibly update webbpsf data cache runs-on: ubuntu-latest env: @@ -49,3 +48,54 @@ jobs: run: | mkdir -p ${{ steps.cache_path.outputs.path }} tar -xzvf tmp/webbpsf-data.tar.gz -C ${{ steps.cache_path.outputs.path }} + data: + needs: + [webbpsf-data] + # run data job if webbpsf-data succeeds or is skipped + if: always() && (needs.webbpsf-data.result == 'success' || needs.webbpsf-data.result == 'skipped') + name: retrieve current CRDS context, and WebbPSF data + runs-on: ubuntu-latest + env: + OBSERVATORY: roman + CRDS_SERVER_URL: https://roman-crds.stsci.edu + # CRDS_PATH here should match DATA_PATH in webbpsf_data.yml + CRDS_PATH: /tmp/data + GH_TOKEN: ${{ github.token }} + outputs: + # TODO simplify data_path and crds_path as they are the same + data_path: ${{ steps.data.outputs.path }} + webbpsf_path: ${{ steps.webbpsf_path.outputs.path }} + data_hash: ${{ steps.data_hash.outputs.hash }} + crds_path: ${{ steps.crds_path.outputs.path }} + crds_context: ${{ steps.crds_context.outputs.pmap }} + crds_server: ${{ steps.crds_server.outputs.url }} + steps: + # crds: + - id: data + run: echo "path=/tmp/data" >> $GITHUB_OUTPUT + - id: crds_context + run: > + echo "pmap=$( + curl -s -X POST -d '{"jsonrpc": "1.0", "method": "get_default_context", "params": ["${{ env.OBSERVATORY }}"], "id": 1}' ${{ env.CRDS_SERVER_URL }}/json/ | + python -c "import sys, json; print(json.load(sys.stdin)['result'])" + )" >> $GITHUB_OUTPUT + # Get default CRDS_CONTEXT without installing crds client + # See https://hst-crds.stsci.edu/static/users_guide/web_services.html#generic-request + - id: crds_path + run: echo "path=${{ env.CRDS_PATH }}" >> $GITHUB_OUTPUT + - id: crds_server + run: echo "url=${{ env.CRDS_SERVER_URL }}" >> $GITHUB_OUTPUT + # webbpsf: + - id: data_hash + run: | + # use actions/gh-actions-cache to allow filtering by key + gh extension install actions/gh-actions-cache + + RECENT=$(gh actions-cache list -R spacetelescope/romancal --key webbpsf- --sort created-at | cut -f 1 | head -n 1) + echo "RECENT=$RECENT" + HASH=$(echo $RECENT | cut -d '-' -f 2) + echo "HASH=$HASH" + echo "hash=$HASH" >> $GITHUB_OUTPUT + if [ "$HASH" == '' ]; then exit 1; fi + - id: webbpsf_path + run: echo "path=${{ steps.data.outputs.path }}/webbpsf-data" >> $GITHUB_OUTPUT