Skip to content

Commit

Permalink
Merge pull request #142 from Wabri/fix/github-action
Browse files Browse the repository at this point in the history
Fix/Refactor: update permission for report and run cc only when secret token is set
  • Loading branch information
angelabriel authored Aug 6, 2024
2 parents 7570900 + fe2f109 commit 0ac5a6a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/saptune-ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ env:
CC_PREFIX: github.com/SUSE/saptune/

jobs:
Check_secrets:
runs-on: ubuntu-latest
outputs:
run_cc: ${{ steps.run_cc.outputs.run_cc }}
steps:
- id: run_cc
run: if [ -z ${CC_TEST_REPORTER_ID} ]; then echo "run_cc=false" >> "$GITHUB_OUTPUT"; else echo "run_cc=true" >> "$GITHUB_OUTPUT"; fi

Setup_Git_Env:
runs-on: ubuntu-latest
needs: Check_secrets
outputs:
branch: ${{ steps.branch.outputs.GIT_BRANCH }}
commit_sha: ${{ steps.commit_sha.outputs.GIT_COMMIT_SHA }}
if: ${{ needs.Check_secrets.outputs.run_cc == 'true' }}
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -46,24 +56,26 @@ jobs:
needs: Setup_Git_Env
steps:
- name: Download test coverage reporter
run: |
curl -L $CC_TEST_REPORTER_URL > ./cc-test-reporter
chmod +x ./cc-test-reporter
run: curl -L $CC_TEST_REPORTER_URL > ./cc-test-reporter

- uses: actions/upload-artifact@v4
with:
name: codeclimate-reporter
path: cc-test-reporter

- name: Grant execution permission to cc-test-reporter
run: chmod +x ./cc-test-reporter

- name: Run the test reporter before-build
env:
GIT_BRANCH: ${{needs.Setup_Git_Env.outputs.branch}}
GIT_COMMIT_SHA: ${{needs.Setup_Git_Env.outputs.commit_sha}}
run: ./cc-test-reporter before-build

Saptune_unit_test:
needs: Code_climate_report_before_build
runs-on: ubuntu-latest
needs: Code_climate_report_before_build
if: ${{ always() }}
steps:
- uses: actions/checkout@v4

Expand All @@ -83,14 +95,15 @@ jobs:
with:
name: coverprofile
path: c.out
if: ${{ env.CC_TEST_REPORTER_ID != '' }}

- name: Stop and remove Container Image
run: |
docker stop saptune-ci
docker rm saptune-ci
Code_climate_report_after_build:
needs: Saptune_unit_test
needs: [Setup_Git_Env, Saptune_unit_test]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
Expand All @@ -101,9 +114,11 @@ jobs:
with:
name: codeclimate-reporter

- name: Grant execution permission to cc-test-reporter
run: chmod +x ./cc-test-reporter

- name: Code Climate report coverage
env:
GIT_BRANCH: ${{needs.Setup_Git_Env.outputs.branch}}
GIT_COMMIT_SHA: ${{needs.Setup_Git_Env.outputs.commit_sha}}
run: ./cc-test-reporter after-build --debug --prefix ${{ env.CC_PREFIX }} --exit-code $?
if: env.CC_TEST_REPORTER_ID != ''

0 comments on commit 0ac5a6a

Please sign in to comment.