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 docker_repo: description: 'The name of the action variable containing the docker repo value' required: false 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}; REPO=${{ github.repository }}; echo "REPO=$REPO" >> "$GITHUB_OUTPUT"; echo "TAG=$BUILD_ID" >> "$GITHUB_OUTPUT"; - name: Print repo and tag 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: | DOCKER_REPO_VALUE="${{ vars[inputs.docker_repo] }}" ISSUE_COMMENT_STRING=`echo "{ \"docker_repo\": \"$DOCKER_REPO_VALUE\", \"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