jsc#TEAM-8703, jsc#SAPSOL-331 - saptune configure #206
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Saptune Continuous Integration | |
# Controls when the workflow will run | |
on: | |
# Triggers the workflow on pull request events but only for the master and sle-12 branch | |
push: | |
branches: [ master, saptune_test ] | |
pull_request: | |
branches: [ master ] | |
env: | |
CC_TEST_REPORTER_URL: https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
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 | |
- name: Set ENV (push) | |
run: | | |
echo "GIT_BRANCH=${{ github.ref }}" >> $GITHUB_ENV | |
echo "GIT_COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV | |
if: github.event_name == 'push' | |
- name: Set ENV (pull_request) | |
run: | | |
git fetch --no-tags --prune --depth=1 origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.head_ref }} | |
echo "GIT_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV | |
echo "GIT_COMMIT_SHA=$(git rev-parse origin/${{ github.head_ref }})" >> $GITHUB_ENV | |
if: github.event_name == 'pull_request' | |
- id: branch | |
run: echo "GIT_BRANCH=${GIT_BRANCH}" >> "$GITHUB_OUTPUT" | |
- id: commit_sha | |
run: echo "GIT_COMMIT_SHA=${GIT_COMMIT_SHA}" >> "$GITHUB_OUTPUT" | |
Code_climate_report_before_build: | |
runs-on: ubuntu-latest | |
needs: Setup_Git_Env | |
steps: | |
- name: Download test coverage 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: | |
runs-on: ubuntu-latest | |
needs: Code_climate_report_before_build | |
if: ${{ always() }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Pull the Container Image | |
run: docker pull registry.opensuse.org/home/angelabriel/st-ci-base/containers/st-ci-base:latest | |
- name: Run Container Image | |
run: docker run --name saptune-ci --privileged --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host -td -v "${{ github.workspace }}:/app" registry.opensuse.org/home/angelabriel/st-ci-base/containers/st-ci-base:latest | |
- name: Get Container Logs | |
run: docker logs saptune-ci | |
- name: Run saptune unit tests | |
run: docker exec -t saptune-ci /bin/sh -c "cd /app; ./run_saptune_ci_tst.sh;" | |
- uses: actions/upload-artifact@v4 | |
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: [Setup_Git_Env, Saptune_unit_test] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: coverprofile | |
- uses: actions/download-artifact@v4 | |
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 $? |