Skip to content

Commit

Permalink
Add build step to post excel on PR's
Browse files Browse the repository at this point in the history
  • Loading branch information
sambles committed Sep 12, 2024
1 parent 35b996a commit 4f6d9f6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 79 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/checkout@v3
if: inputs.ods_branch == ''
with:
ref: ${{ github.ref_name }}
ref: ${{ github.ref }}

- name: Clone (workflow_call)
uses: actions/checkout@v3
Expand All @@ -58,14 +58,14 @@ jobs:
run: ./utils/gen-excel.py --source-csv-dir ${{ env.SPEC_PATH_IN }} --output-path ${{ env.EXCEL_PATH_OUT }}

- name: Store JSON
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: extracted_spec
path: ${{ env.JSON_PATH_OUT }}
retention-days: 14

- name: Store Excel
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: excel_spec
path: ${{ env.EXCEL_PATH_OUT }}
Expand Down
74 changes: 0 additions & 74 deletions .github/workflows/pr-add-artifact.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
git tag ${{ env.RELEASE_TAG }}
- name: Download JSON spec
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: extracted_spec
path: ${{ github.workspace }}/
Expand Down
66 changes: 65 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: OpenData Testing

on:
push:
pull_request:
workflow_dispatch:
inputs:
ods_tools_branch:
Expand All @@ -24,6 +25,69 @@ jobs:
oed_spec_json: ${{ needs.build_spec.outputs.spec_filename }}
ods_branch: ${{ github.event_name != 'workflow_dispatch' && 'main' || inputs.ods_tools_branch }}


attach_pr:
if: github.event_name == 'pull_request'
name: Update PR
needs: build_spec
runs-on: ubuntu-latest

steps:
- name: Github context
run: echo "$GITHUB_CONTEXT"
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}

- name: Get Artifact URL & PR Info
env:
GITHUB_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
JOB_ID: ${{ github.run_id }}
PR_NUMBER: ${{ github.event.number }}
HEAD_SHA: ${{ github.sha }}
run: |
echo "Job ID: $JOB_ID"
echo "JOB_ID=$JOB_ID" >> "$GITHUB_ENV"
EXCEL_ID=$(gh api "/repos/OasisLMF/ODS_OpenExposureData/actions/artifacts" --jq '.artifacts[] | select(.workflow_run.id == '$JOB_ID') | select(.expired == false) | select(.name | startswith("excel_spec")) | .id')
echo "EXCEL ID: $EXCEL_ID"
echo "EXCEL_ID=$EXCEL_ID" >> "$GITHUB_ENV"
JSON_ID=$(gh api "/repos/OasisLMF/ODS_OpenExposureData/actions/artifacts" --jq '.artifacts[] | select(.workflow_run.id == '$JOB_ID') | select(.expired == false) | select(.name | startswith("extracted_spec")) | .id')
echo "JSON ID: $JSON_ID"
echo "JSON_ID=$JSON_ID" >> "$GITHUB_ENV"
echo "PR Number: $PR_NUMBER"
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV"
echo "Head sha: $HEAD_SHA"
echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV"
- name: Update Comment
env:
JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/\
runs/${{ env.JOB_ID }}"
HEAD_SHA: ${{ env.HEAD_SHA }}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ env.PR_NUMBER }}
body: |-
## Build Preview
You can find files attached to the below linked Workflow Run URL (Logs).
Please note that files only stay for around 14 days!
| Name | Link
------------|-------------------------------------------------------
| Commit | ${{ env.HEAD_SHA }}
| Build | ${{ env.JOB_PATH }}
| Excel File | [excel_spec.zip](https://github.com/OasisLMF/ODS_OpenExposureData/actions/runs/${{ env.JOB_ID }}/artifacts/${{ env.EXCEL_ID }})
| JSON File | [extracted_spec.zip](https://github.com/OasisLMF/ODS_OpenExposureData/actions/runs/${{ env.JOB_ID }}/artifacts/${{ env.JSON_ID }})
[badge]: https://img.shields.io/badge/Build-Success!-3fb950?logo=github&style=for-the-badge
test:
name: Run Pytest
runs-on: ubuntu-latest
Expand All @@ -45,7 +109,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Download package
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: bin_package
path: ${{ github.workspace }}/
Expand Down

0 comments on commit 4f6d9f6

Please sign in to comment.