From 988d51d9d37efff2cd4d56a84ba77d747746c950 Mon Sep 17 00:00:00 2001 From: Yu-Hang 'Maxin' Tang Date: Wed, 6 Sep 2023 01:02:53 +0100 Subject: [PATCH] new badge publish mechanism --- .github/workflows/_publish_badge_v2.yaml | 58 +++++++++++++++++++ .github/workflows/_sandbox.yaml | 18 ++---- .github/workflows/_test_jax.yaml | 36 +++++++----- .../{_util.sh => scripts/to_json.sh} | 0 4 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/_publish_badge_v2.yaml rename .github/workflows/{_util.sh => scripts/to_json.sh} (100%) diff --git a/.github/workflows/_publish_badge_v2.yaml b/.github/workflows/_publish_badge_v2.yaml new file mode 100644 index 000000000..dabb2e398 --- /dev/null +++ b/.github/workflows/_publish_badge_v2.yaml @@ -0,0 +1,58 @@ +name: ~publish test results into a shields.io endpoint json file + +on: + workflow_call: + inputs: + BADGE_FILES: + type: string + description: 'Name/wildcard pattern for shields.io endpoint JSON' + required: true + # outputs: + # GIST_ID: + # description: 'Id of the GitHub Gist that hosts all endpoint JSON files' + # value: ${{ jobs.publish.outputs.STATUS }} + +jobs: + publish: + runs-on: ubuntu-22.04 + # outputs: + # STATUS: ${{ steps.script.outputs.STATUS }} + steps: + - name: Download artifacts specified by input + uses: actions/download-artifact@v3 + + - name: Update status badge file in gist + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.NVJAX_GIST_TOKEN }} + script: | + const fs = require('fs').promises; + const filesInDirectory = await fs.readdir('.'); + const matchingFiles = filesInDirectory.filter( + filename => filename.includes(${{ inputs.BADGE_FILES }}) + ); + const filesToCreate = await Promise.all( + matchingFiles.map( + async filename => { + const content = await fs.readFile(filename, 'utf8'); + return [filename, { content }]; + } + ) + ); + + const currentDateTime = new Date().toISOString(); + const gistDescription = + `Badge endpoint files from Workflow: ${{ github.workflow }}, ` + + `Run ID: ${{ github.run_id }}, ` + + `Repository: ${{ github.repository }}, ` + + `Event: ${{ github.event_name }}, ` + + `Created: ${currentDateTime}`; + + gist = await github.rest.gists.create({ + description: gistDescription, + public: false, + files: Object.fromEntries(filesToCreate) + }); + + console.log(gist) + // return gist.data.id; diff --git a/.github/workflows/_sandbox.yaml b/.github/workflows/_sandbox.yaml index 7636e8771..1caa5b7d5 100644 --- a/.github/workflows/_sandbox.yaml +++ b/.github/workflows/_sandbox.yaml @@ -33,16 +33,8 @@ jobs: cat "$f" | jq -r '.summary' | tee -a $GITHUB_STEP_SUMMARY done - # publish-badge: - # needs: [run-jobs] - # strategy: - # fail-fast: false - # matrix: - # GPU_ARCH: [V100, A100] - # uses: ./.github/workflows/_publish_badge_v2.yaml - # if: always() - # secrets: inherit - # with: - # ENDPOINT_FILENAME: 'jax-unit-test-status-${{ matrix.GPU_ARCH }}.json' - # PUBLISH: false - \ No newline at end of file + publish-badge: + needs: [run-jobs] + uses: ./.github/workflows/_publish_badge_v2.yaml + if: always() + secrets: inherit diff --git a/.github/workflows/_test_jax.yaml b/.github/workflows/_test_jax.yaml index 7e718f0b8..5690c9724 100644 --- a/.github/workflows/_test_jax.yaml +++ b/.github/workflows/_test_jax.yaml @@ -8,10 +8,16 @@ on: description: 'JAX image built by NVIDIA/JAX-Toolbox' required: true default: 'ghcr.io/nvidia/jax:latest' - outputs: - ARTIFACTS: - description: 'Name of the unit test artifact for downstream workflows' - value: ${{ jobs.unit-test.outputs.ARTIFACTS }} + ARTIFACT_NAME: + type: string + description: 'Name of the artifact zip file' + required: false + default: 'jax-unit-test-logs' + BADGE_FILENAME: + type: string + description: 'Name of the endpoint JSON file for shields.io badge' + required: false + default: 'jax-unit-test-badge' jobs: @@ -32,9 +38,7 @@ jobs: # runs-on: [self-hosted, "${{ matrix.GPU_ARCH == 'A100' && format('{0}:{1}', matrix.GPU_ARCH, github.run_id) || matrix.GPU_ARCH }}"] runs-on: ubuntu-22.04 env: - ARTIFACTS: 'jax-unit-test-logs' - outputs: - ARTIFACTS: ${{ env.ARTIFACTS }} + BADGE_FILENAME_FULL: ${{ inputs.BADGE_FILENAME }}-${{ matrix.GPU_ARCH }}.json steps: - name: Print environment variables run: env @@ -78,12 +82,8 @@ jobs: - name: Generate job summary for unit test shell: bash -x -e {0} run: | - pwd - - ls -lR - # bring in utility functions - . .github/workflows/_util.sh + source .github/workflows/scripts/to_json.sh badge_label='${{ matrix.GPU_ARCH }} Unit' @@ -112,11 +112,19 @@ jobs: badge_label badge_color badge_message \ > sitrep.json + schemaVersion=1 \ + label="${badge_label}" \ + message="${badge_message}" \ + color="${badge_color}" \ + to_json schemaVersion label message color \ + > ${{ env.BADGE_FILENAME_FULL }} + - name: Upload test logs uses: actions/upload-artifact@v3 with: - name: ${{ env.ARTIFACTS }}-${{ matrix.GPU_ARCH }} + name: ${{ inputs.ARTIFACT_NAME }}-${{ matrix.GPU_ARCH }} path: | - sitrep.json test-backend-independent.log test-gpu.log + sitrep.json + ${{ env.BADGE_FILENAME_FULL }} diff --git a/.github/workflows/_util.sh b/.github/workflows/scripts/to_json.sh similarity index 100% rename from .github/workflows/_util.sh rename to .github/workflows/scripts/to_json.sh