Skip to content

Commit

Permalink
Use env var for head_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Aug 26, 2024
1 parent 74edbeb commit fb4140c
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions .github/workflows/solidity-foundry-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ on:

env:
FOUNDRY_PROFILE: ci
# Unfortunately, we can't use the "default" field in the inputs section, because it does not have
# access to the workflow context
head_ref: ${{ inputs.commit_to_use || github.sha }}

jobs:
changes:
Expand All @@ -42,7 +45,7 @@ jobs:
- name: Checkout the repo
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
ref: ${{ inputs.commit_to_use || github.sha }}
ref: ${{ env.head_ref }}
- name: Find modified contracts
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: changes-dorny
Expand Down Expand Up @@ -144,13 +147,13 @@ jobs:
shell: bash
run: |
echo "Product: ${{ inputs.product }}" > contracts/commit_sha_base_ref.txt
echo "Commit SHA used to generate artifacts: ${{ inputs.commit_to_use || github.sha }}" >> contracts/commit_sha_base_ref.txt
echo "Commit SHA used to generate artifacts: ${{ env.head_ref }}" >> contracts/commit_sha_base_ref.txt
echo "Base reference SHA used to find modified contracts: ${{ inputs.base_ref }}" >> contracts/commit_sha_base_ref.txt
IFS=',' read -r -a modified_files <<< "${{ needs.changes.outputs.product_files }}"
echo "# Modified contracts:" > contracts/modified_contracts.md
for file in "${modified_files[@]}"; do
echo " - [$file](${{ github.server_url }}/${{ github.repository }}/blob/${{ inputs.commit_to_use || github.sha }}/$file)" >> contracts/modified_contracts.md
echo " - [$file](${{ github.server_url }}/${{ github.repository }}/blob/${{ env.head_ref }}/$file)" >> contracts/modified_contracts.md
echo "$file" >> contracts/modified_contracts.txt
done
Expand Down Expand Up @@ -187,7 +190,7 @@ jobs:
- name: Checkout the repo
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
ref: ${{ inputs.commit_to_use || github.sha }}
ref: ${{ env.head_ref }}

- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
Expand Down Expand Up @@ -268,7 +271,7 @@ jobs:
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
fetch-depth: 0
ref: ${{ inputs.commit_to_use || github.sha }}
ref: ${{ env.head_ref }}

- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
Expand Down Expand Up @@ -315,7 +318,7 @@ jobs:
cp contracts/foundry.toml foundry.toml
echo "::debug::Processing contracts: $contract_list"
./contracts/scripts/ci/generate_slither_report.sh "${{ github.server_url }}/${{ github.repository }}/blob/${{ inputs.commit_to_use || github.sha }}/" contracts/configs/slither/.slither.config-artifacts.json "." "$contract_list" "contracts/slither-reports" "--solc-remaps @=contracts/node_modules/@"
./contracts/scripts/ci/generate_slither_report.sh "${{ github.server_url }}/${{ github.repository }}/blob/${{ env.head_ref }}/" contracts/configs/slither/.slither.config-artifacts.json "." "$contract_list" "contracts/slither-reports" "--solc-remaps @=contracts/node_modules/@"
- name: Upload UMLs and Slither reports
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
Expand Down Expand Up @@ -346,7 +349,7 @@ jobs:
- name: Checkout the repo
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
ref: ${{ inputs.commit_to_use || github.sha }}
ref: ${{ env.head_ref }}

- name: Download all artifacts
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
Expand All @@ -357,7 +360,7 @@ jobs:
- name: Upload all artifacts as single package
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
name: review-artifacts-${{ inputs.product }}-${{ inputs.base_ref }}-${{ inputs.commit_to_use || github.sha }}
name: review-artifacts-${{ inputs.product }}-${{ inputs.base_ref }}-${{ env.head_ref }}
path: review_artifacts

- name: Remove temporary artifacts
Expand All @@ -371,13 +374,13 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ARTIFACTS=$(gh api -X GET repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts)
ARTIFACT_ID=$(echo "$ARTIFACTS" | jq '.artifacts[] | select(.name=="review-artifacts-${{ inputs.product }}-${{ inputs.commit_to_use || github.sha }}") | .id')
ARTIFACT_ID=$(echo "$ARTIFACTS" | jq '.artifacts[] | select(.name=="review-artifacts-${{ inputs.product }}-${{ env.head_ref }}") | .id')
echo "Artifact ID: $ARTIFACT_ID"
echo "# Solidity Review Artifact Generated" >> $GITHUB_STEP_SUMMARY
echo "Product: **${{ inputs.product }}**" >> $GITHUB_STEP_SUMMARY
echo "Base Ref used: **${{ inputs.base_ref }}**" >> $GITHUB_STEP_SUMMARY
echo "Commit SHA used: **${{ inputs.commit_to_use || github.sha }}**" >> $GITHUB_STEP_SUMMARY
echo "Commit SHA used: **${{ env.head_ref }}**" >> $GITHUB_STEP_SUMMARY
artifact_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/$ARTIFACT_ID"
echo "[Artifact URL]($artifact_url)" >> $GITHUB_STEP_SUMMARY
Expand All @@ -398,7 +401,7 @@ jobs:
CHANGESET_FILES: ${{ needs.changes.outputs.changeset_files }}
CHAINLINK_PRODUCT: ${{ inputs.product }}
BASE_REF: ${{ inputs.base_ref }}
HEAD_REF: ${{ inputs.commit_to_use || github.sha }}
HEAD_REF: ${{ env.head_ref }}
ARTIFACT_URL: ${{ steps.gather-all-artifacts.outputs.artifact-url }}

JIRA_HOST: https://smartcontract-it.atlassian.net/
Expand All @@ -417,9 +420,9 @@ jobs:
run: |
echo "# Solidity Review Artifact NOT Generated" >> $GITHUB_STEP_SUMMARY
echo "Base Ref used: **${{ inputs.base_ref }}**" >> $GITHUB_STEP_SUMMARY
echo "Commit SHA used: **${{ inputs.commit_to_use || github.sha }}**" >> $GITHUB_STEP_SUMMARY
echo "Commit SHA used: **${{ env.head_ref }}**" >> $GITHUB_STEP_SUMMARY
echo "## Reason: No modified Solidity files found for ${{ inputs.product }}" >> $GITHUB_STEP_SUMMARY
echo "* no modified Solidity files found between ${{ inputs.base_ref }} and ${{ inputs.commit_to_use || github.sha }} commits" >> $GITHUB_STEP_SUMMARY
echo "* no modified Solidity files found between ${{ inputs.base_ref }} and ${{ env.head_ref }} commits" >> $GITHUB_STEP_SUMMARY
echo "* or they are located outside of ./contracts/src/v0.8 folder" >> $GITHUB_STEP_SUMMARY
echo "* or they were limited to test files" >> $GITHUB_STEP_SUMMARY
exit 1

0 comments on commit fb4140c

Please sign in to comment.