diff --git a/.github/workflows/issue-closed.yml b/.github/workflows/issue-closed.yml deleted file mode 100644 index f9341cc..0000000 --- a/.github/workflows/issue-closed.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -name: Run VM-MANAGER-RELEASE-FLOW - - -on: - issues: - types: - - closed - branches: "**" -permissions: read-all -jobs: - If_IssueClosed: - uses: projectceladon/celadonworkflows/.github/workflows/trigger_ci.yml@v1.0 - with: - EVENT: ${{ toJSON(github.event) }} diff --git a/.github/workflows/pr-approved.yml b/.github/workflows/pr-approved.yml deleted file mode 100644 index bbf09db..0000000 --- a/.github/workflows/pr-approved.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -name: Run VM-MANAGER-PR-MERGE-FLOW - -on: - pull_request_review: - types: [submitted] - branches: - - master - - tmp/ci-testing -permissions: read-all -jobs: - if_approved: - if: github.event.review.state == 'approved' && github.event.pull_request.base.ref == 'master' || github.event.pull_request.base.ref == 'tmp/ci-testing' - uses: projectceladon/celadonworkflows/.github/workflows/trigger_ci.yml@v1.0 - with: - EVENT: ${{ toJSON(github.event) }} \ No newline at end of file diff --git a/.github/workflows/pr-raised.yml b/.github/workflows/pr-raised.yml deleted file mode 100644 index cf5a056..0000000 --- a/.github/workflows/pr-raised.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -name: Run VM-MANAGER-PR-FLOW - -on: - pull_request: - types: [opened, synchronize, reopened, edited] - branches: "**" -permissions: read-all -jobs: - Trigger-Worflows: - uses: projectceladon/celadonworkflows/.github/workflows/trigger_ci.yml@v1.0 - with: - EVENT: ${{ toJSON(github.event) }} \ No newline at end of file diff --git a/.github/workflows/publish_pr_events.yml b/.github/workflows/publish_pr_events.yml new file mode 100644 index 0000000..ad9e29c --- /dev/null +++ b/.github/workflows/publish_pr_events.yml @@ -0,0 +1,72 @@ +name: CI Workflow + +on: + pull_request_target: + types: [opened, synchronize, reopened, edited] + branches: "**" + issues: + types: + - closed + 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 new file mode 100644 index 0000000..41de886 --- /dev/null +++ b/.github/workflows/publish_review_event.yaml @@ -0,0 +1,96 @@ +name: Publish Review Event + +on: + workflow_run: + workflows: ["Store_Review_Event"] + types: + - completed +permissions: read-all + +jobs: + fetch_and_process: + runs-on: ubuntu-latest + steps: + - name: 'Download artifact' + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "eventjson" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/eventjson.zip`, Buffer.from(download.data)); + + - name: 'Unzip artifact' + run: | + ls + unzip eventjson.zip + + - 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=$(cat event.json) + + 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 "$EVENT_DATA"; 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 \ No newline at end of file diff --git a/.github/workflows/store_review_event.yaml b/.github/workflows/store_review_event.yaml new file mode 100644 index 0000000..3cdf271 --- /dev/null +++ b/.github/workflows/store_review_event.yaml @@ -0,0 +1,28 @@ +name: Store_Review_Event + +on: + pull_request_review: + types: [submitted] + branches: + - master + - tmp/ci-testing +permissions: read-all + +jobs: + Store_Review_Event: + 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