From 9461d5ec02e360d090e8744d3c49be40b4cde090 Mon Sep 17 00:00:00 2001 From: ypoplavs Date: Tue, 6 Aug 2024 11:41:29 +0300 Subject: [PATCH 1/2] add outputs to sandbox --- .github/sandbox-comment-template.md | 9 ++++ .github/workflows/dispatch-sandbox-push.yaml | 49 ++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/sandbox-comment-template.md diff --git a/.github/sandbox-comment-template.md b/.github/sandbox-comment-template.md new file mode 100644 index 000000000..ef6fc7b2b --- /dev/null +++ b/.github/sandbox-comment-template.md @@ -0,0 +1,9 @@ +Sandbox environment for `{{ .branch_ref }}` has been created. + +## URLs + +- **Dashboard**: https://dashboard.{{ .branch_ref }}.testkube.dev +- **API**: https://api.{{ .branch_ref }}.testkube.dev +- **Agent**: https://agent.{{ .branch_ref }}.testkube.dev +- **Storage**: https://storage.{{ .branch_ref }}.testkube.dev +- **Websockets**: https://websockets.{{ .branch_ref }}.testkube.dev diff --git a/.github/workflows/dispatch-sandbox-push.yaml b/.github/workflows/dispatch-sandbox-push.yaml index c3215f159..2e2594d38 100644 --- a/.github/workflows/dispatch-sandbox-push.yaml +++ b/.github/workflows/dispatch-sandbox-push.yaml @@ -4,21 +4,70 @@ on: push: branches: - sandbox/** + pull_request: + types: + - opened jobs: dispatch: runs-on: ubuntu-latest steps: - uses: actions/create-github-app-token@v1 + if: startsWith(github.ref, 'refs/heads/sandbox/') id: app-token with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.PRIVATE_KEY }} owner: ${{ github.repository_owner }} + - name: Repository dispatch + if: startsWith(github.ref, 'refs/heads/sandbox/') uses: peter-evans/repository-dispatch@v2 with: token: ${{ steps.app-token.outputs.token }} repository: kubeshop/testkube-deployment event-type: sandbox_agent_charts_update client-payload: '{"ref": "${{ github.ref }}", "ref_name": "${{ github.ref_name }}", "agent_sha": "${{ github.sha }}", "repository": "${{ github.repository }}"}' + + - name: Output summary + if: startsWith(github.ref, 'refs/heads/sandbox/') + run: | + echo -e "### Sandbox Environment" >> $GITHUB_STEP_SUMMARY + echo -e '```' >> $GITHUB_STEP_SUMMARY + echo -e "## URLs" >> $GITHUB_STEP_SUMMARY + echo "- Dashboard: https://dashboard.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- API: https://api.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- Agent: https://agent.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- Storage: https://storage.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- Websockets: https://websockets.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo -e '```' >> $GITHUB_STEP_SUMMARY + + - name: Get a branch name if PR is created + if: startsWith(github.event.pull_request.head.ref, 'sandbox/') + run: | + # get a branch name + branch_ref="${{ github.event.pull_request.head.ref }}" + + #remove slash + branch_ref="${branch_ref#*/}" + + #create env var + echo "branch_ref=$branch_ref" >> $GITHUB_ENV + + - name: Render template + if: startsWith(github.event.pull_request.head.ref, 'sandbox/') + id: template + uses: chuhlomin/render-template@v1.4 + with: + template: .github/comment-template.md + vars: | + branch_ref: ${{ env.branch_ref }} + + - name: Create comment on a PR with the endpoints + if: startsWith(github.event.pull_request.head.ref, 'sandbox/') + uses: peter-evans/create-or-update-comment@v4 + with: + token: ${{ secrets.CI_BOT_TOKEN }} + issue-number: ${{ github.event.pull_request.number }} + body: ${{ steps.template.outputs.result }} + From bac2f83a1c31b30a60ba2adac68caee4dae44496 Mon Sep 17 00:00:00 2001 From: ypoplavs Date: Tue, 6 Aug 2024 14:23:12 +0300 Subject: [PATCH 2/2] add missing step --- .github/workflows/dispatch-sandbox-push.yaml | 22 +++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dispatch-sandbox-push.yaml b/.github/workflows/dispatch-sandbox-push.yaml index 2e2594d38..71c366dc5 100644 --- a/.github/workflows/dispatch-sandbox-push.yaml +++ b/.github/workflows/dispatch-sandbox-push.yaml @@ -29,17 +29,29 @@ jobs: event-type: sandbox_agent_charts_update client-payload: '{"ref": "${{ github.ref }}", "ref_name": "${{ github.ref_name }}", "agent_sha": "${{ github.sha }}", "repository": "${{ github.repository }}"}' + - name: Set version + if: startsWith(github.ref, 'refs/heads/sandbox/') + run: | + #get short commit sha that triggered the flow + echo git_hash="$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV + + # Extract everything before the first slash + branch_identifier=$(echo "$GITHUB_REF_NAME" | cut -d'/' -f2-) + + # Replace slashes with dashes using sed + echo branch_identifier=$(echo "$branch_identifier" | sed 's/\//-/g') >> $GITHUB_ENV + - name: Output summary if: startsWith(github.ref, 'refs/heads/sandbox/') run: | echo -e "### Sandbox Environment" >> $GITHUB_STEP_SUMMARY echo -e '```' >> $GITHUB_STEP_SUMMARY echo -e "## URLs" >> $GITHUB_STEP_SUMMARY - echo "- Dashboard: https://dashboard.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY - echo "- API: https://api.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY - echo "- Agent: https://agent.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY - echo "- Storage: https://storage.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY - echo "- Websockets: https://websockets.${{ github.ref_name }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- Dashboard: https://dashboard.${{ env.branch_identifier }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- API: https://api.${{ env.branch_identifier }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- Agent: https://agent.${{ env.branch_identifier }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- Storage: https://storage.${{ env.branch_identifier }}.testkube.dev" >> $GITHUB_STEP_SUMMARY + echo "- Websockets: https://websockets.${{ env.branch_identifier }}.testkube.dev" >> $GITHUB_STEP_SUMMARY echo -e '```' >> $GITHUB_STEP_SUMMARY - name: Get a branch name if PR is created