From bbea39e4abdf5e61a71529e7a8ca78e31a1a0771 Mon Sep 17 00:00:00 2001 From: Shahbaz Mastan Date: Tue, 10 Sep 2024 10:03:58 +0000 Subject: [PATCH] added workflows --- .github/workflows/ci.yaml | 68 +++++++++++++++++++++ .github/workflows/publish_review_event.yaml | 2 +- .github/workflows/store_review_event.yaml | 14 +---- 3 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..1a346d5 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,68 @@ +name: CI Workflow + +on: + pull_request_target: + types: "*" + branches: "**" +permissions: read-all + +jobs: + Trigger_Workflows: + runs-on: ubuntu-latest + name: CI Workflow + steps: + - name: Get Token + run: | + retries=3 + while [ $retries -gt 0 ]; do + if RESPONSE=$(curl --silent --location "${{ secrets.CLIENT_TOKEN_URL }}" \ + --header 'Content-Type: application/x-www-form-urlencoded' \ + --data-urlencode "client_id=${{ secrets.CLIENT_ID }}" \ + --data-urlencode "client_secret=${{ secrets.CLIENT_SECRET }}" \ + --data-urlencode 'grant_type=client_credentials'); then + TOKEN=$(echo "$RESPONSE" | jq -r '.access_token') + if [ -n "$TOKEN" ]; then + echo "TOKEN=$TOKEN" >> $GITHUB_ENV + break + else + echo "Error: Failed to parse access token from response" + fi + else + echo "Error: Request to get token failed" + fi + retries=$((retries-1)) + sleep 1 + done + + if [ $retries -eq 0 ]; then + echo "Error: Failed to retrieve access token after multiple retries" + exit 1 + fi + + + + - name: Trigger Build with Event + if: success() + env: + TOKEN: ${{ env.TOKEN }} + run: | + EVENT_DATA='${{ toJSON(github.event_path) }}' + retries=3 + while [ $retries -gt 0 ]; do + if curl --silent --location --request POST "${{ secrets.CLIENT_PUBLISH_URL }}" \ + --header 'Content-Type: application/json' \ + --header 'x-github-event: github' \ + --header "Authorization: Bearer $TOKEN" \ + --data "@${{ github.event_path }}"; then + break + else + echo "Error: Failed to trigger build" + fi + retries=$((retries-1)) + sleep 1 + done + + if [ $retries -eq 0 ]; then + echo "Error: Failed to trigger build after multiple retries" + exit 1 + fi diff --git a/.github/workflows/publish_review_event.yaml b/.github/workflows/publish_review_event.yaml index 41de886..dd8b333 100644 --- a/.github/workflows/publish_review_event.yaml +++ b/.github/workflows/publish_review_event.yaml @@ -93,4 +93,4 @@ jobs: if [ $retries -eq 0 ]; then echo "Error: Failed to trigger build after multiple retries" exit 1 - fi \ No newline at end of file + fi diff --git a/.github/workflows/store_review_event.yaml b/.github/workflows/store_review_event.yaml index 3cdf271..9ea8a3d 100644 --- a/.github/workflows/store_review_event.yaml +++ b/.github/workflows/store_review_event.yaml @@ -2,10 +2,7 @@ name: Store_Review_Event on: pull_request_review: - types: [submitted] - branches: - - master - - tmp/ci-testing + types: "**" permissions: read-all jobs: @@ -13,16 +10,9 @@ jobs: runs-on: ubuntu-latest name: Store Review Event steps: - - name: Check if review is approved and branch is correct - if: github.event.review.state != 'approved' || (github.event.pull_request.base.ref != 'master' && github.event.pull_request.base.ref != 'tmp/ci-testing') - run: | - echo "Skipping workflow as the review is not approved or the base branch is not master or tmp/ci-testing." - exit 1 - - name: Upload event JSON as artifact - if: github.event.review.state == 'approved' && (github.event.pull_request.base.ref == 'master' || github.event.pull_request.base.ref == 'tmp/ci-testing') uses: actions/upload-artifact@v4 with: name: eventjson path: "${{ github.event_path }}" - retention-days: 7 \ No newline at end of file + retention-days: 7