github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/.github/workflows/release_summary.yml (about) 1 name: Post release summary for the day 2 run-name: Posting the releases in Slack once a day 3 on: 4 schedule: 5 - cron: "0 16 * * 1-5" 6 workflow_dispatch: 7 8 jobs: 9 publish-release: 10 runs-on: ubuntu-latest 11 steps: 12 - name: Compile the releases for the day and compose the message 13 id: compose_message 14 run: | 15 today=$(date +%Y-%m-%d) 16 17 data=$(curl -L \ 18 -H "Accept: application/vnd.github+json" \ 19 -H "X-GitHub-Api-Version: 2022-11-28" \ 20 https://api.github.com/repos/instana/go-sensor/releases?per_page=30 \ 21 | jq -r --arg today "$today" '.[] | select(.published_at | startswith($today)) | select(.body | test("--auto-generated--") | not) | "name:\(.name), url:\(.html_url)"') 22 23 if [[ $data == "" ]]; then 24 echo "No releases for the day" 25 exit 0 26 fi 27 28 transform_message() { 29 local input="$1" 30 local name="" 31 local version="" 32 if [[ $input != *"instrumentation"* ]]; then 33 name="go-sensor/core" 34 version=$(echo "$input" | sed -n 's/.*name:\([^,]*\),.*/\1/p') 35 else 36 name=$(echo "$input" | sed -n 's/^name:instrumentation\/\(.*\)\/v\([^,]*\),.*$/\1/p') 37 version=$(echo "$input" | sed -n 's/^name:instrumentation\/.*\/v\([^,]*\),.*$/\1/p') 38 fi 39 40 local url=$(echo "$input" | sed -n 's/^.*url:\([^,]*\)$/\1/p') 41 42 echo "- $name - <$url|$version>\n" 43 } 44 45 final_msg="" 46 while IFS= read -r line; do 47 transformed_line=$(transform_message "$line") 48 final_msg="$final_msg$transformed_line\n" 49 done <<< "$data" 50 51 MESSAGE='[{"type":"section","text":{"type":"mrkdwn","text":":mega: *GoTracer Team* has released the following packages on *'"$today"'*"}},{"type":"section","text":{"type":"mrkdwn","text":"'"$final_msg"'"}}]' 52 echo "RELEASE_CONTENT=$final_msg" >> $GITHUB_ENV 53 echo "MESSAGE=$MESSAGE" >> $GITHUB_ENV 54 55 - name: Send success message to tracer release channel 56 id: send_message 57 run: | 58 echo "Release content: $RELEASE_CONTENT" 59 if [[ $RELEASE_CONTENT == "" ]];then exit 0; fi 60 61 curl -H "Content-type: application/json" \ 62 --data '{"channel":"'"$SLACK_CHANNEL_ID"'","blocks":'"$MESSAGE"'}' \ 63 -H "Authorization: Bearer $SLACK_BOT_TOKEN" \ 64 -X POST https://slack.com/api/chat.postMessage 65 env: 66 SLACK_BOT_TOKEN: ${{secrets.SLACK_BOT_TOKEN }} 67 SLACK_CHANNEL_ID: ${{secrets.SLACK_TEST_CHANNEL_ID }} 68 MESSAGE: ${{ env.MESSAGE }} 69 RELEASE_CONTENT: ${{ env.RELEASE_CONTENT }} 70