deploy-tools/.github/workflows/cs-update-trigger.yml
Sahil Ahuja 298c951b19 Fix
2025-03-06 23:02:50 +05:30

54 lines
2.0 KiB
YAML

name: Reusable container push workflow
#This workflow is called from the repo that contains the source code
on:
workflow_call:
inputs:
deploy_repo:
description: 'The cs repo that contains this image'
required: true
type: string
jobs:
trigger-cs-job:
permissions:
issues: write
runs-on: ubuntu-22.04
steps:
- id: get-id
name: Get a unique tag for this build
run: |
SHA=${{ github.sha }}; BRANCH_NAME=${{ github.base_ref || github.ref_name }};
BUILD_ID=$BRANCH_NAME-${SHA:0:8};
echo "REPO=${{ github.repository }}" >> $GITHUB_OUTPUT";
echo "TAG=$BUILD_ID" >> "$GITHUB_OUTPUT";
- name: Print repo and build_id
run: |
echo "REPO: ${{ steps.get-id.outputs.REPO }}";
echo "TAG: ${{ steps.get-id.outputs.TAG }}";
- name: Push image name and tag to cs repo's latest issue with label workflow
run: |
ISSUE_COMMENT_STRING=`echo "{ \"repo\": \"${{ steps.get-id.outputs.REPO }}\", \"tag\": \"${{ steps.get-id.outputs.TAG }}\", \"sender\": \"${{ github.event.sender.login }}\" }" | jq tostring`
echo ISSUE_COMMENT_STRING: $ISSUE_COMMENT_STRING
API_JSON_BODY=`echo '{"body": '$ISSUE_COMMENT_STRING' }' | jq -r tostring`
echo API_JSON_BODY: $API_JSON_BODY
# {"body":"{\"image\":\"repo2.hub.gmetri.io/dt-api\",\"tag\":\"main-255c2f30\"}"}
set -x
ISSUE_JSON=`curl -X 'GET' \
'${{ github.api_url }}/repos/${{ inputs.deploy_repo }}/issues?labels=workflow&page=1&limit=1' \
-H 'accept: application/json' \
-H 'Authorization: token ${{ secrets.bot_build_issues_token }}'`
ISSUE_NUMBER=`echo $ISSUE_JSON | jq '.[0].number'`
curl -X 'POST' \
'${{ github.api_url }}/repos/${{ inputs.deploy_repo }}/issues/'$ISSUE_NUMBER'/comments' \
-H 'accept: application/json' \
-H 'Authorization: token ${{ secrets.bot_build_issues_token }}' \
-H 'Content-Type: application/json' \
-d $API_JSON_BODY
set +x