Skip to content

Commit f6d66a0

Browse files
committed
Add a wordflow to update Quarkus Insights videos
1 parent ab5e946 commit f6d66a0

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Update Insights Sessions archive/upcoming
2+
3+
on:
4+
schedule:
5+
- cron: '0 * * * 1'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
18+
19+
- name: Archive current session
20+
id: archive_session
21+
env:
22+
YOUTUBE_API_KEY: ${{ secrets.INSIGHTS_YOUTUBE_API_KEY }}
23+
YOUTUBE_CHANNEL_ID: ${{ secrets.INSIGHTS_YOUTUBE_CHANNEL_ID }}
24+
run: |
25+
today=$(date +"%B %d, %Y")
26+
27+
nextsessiondate=$(yq -r '.nextsessiondate' _data/insights-videos.yaml)
28+
nextsessiondate_formatted=$(date --date=$nextsessiondate +"%B %d, %Y")
29+
30+
if [ "$today" != "$nextsessiondate_formatted" ]; then
31+
echo "Next session date ($nextsessiondate_formatted) does not match today's date ($today). Skipping workflow run."
32+
exit 0
33+
fi
34+
35+
current_episode=$(yq -r '.nextsessiontitle | sub(".* #([0-9]+):.*"; "${1}")' _data/insights-videos.yaml)
36+
echo $current_episode
37+
38+
youtube_response=$(curl -s --fail \
39+
-H "X-goog-api-key: ${YOUTUBE_API_KEY}" \
40+
"https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${YOUTUBE_CHANNEL_ID}&q=%23${current_episode}&type=video")
41+
42+
video_id=$(echo $youtube_response | jq -r '.items[0].id.videoId')
43+
video_status=$(echo $youtube_response | jq -r '.items[0].snippet.liveBroadcastContent')
44+
video_title=$(echo $youtube_response | jq -r '.items[0].snippet.title')
45+
46+
# Check if a video ID was found
47+
if [ -z "$video_id" ] || [ "$video_id" == "null" ]; then
48+
echo "Could not find the YouTube video for episode #$current_episode. Assuming it's not there yet. Exiting..."
49+
exit 0
50+
fi
51+
52+
if [[ "$video_title" == *"#$current_episode"* ]]; then
53+
echo "The video title contains the required episode number: '#$current_episode'"
54+
else
55+
echo "The video title does NOT contain the required episode number: '#$current_episode'. Exiting..."
56+
exit 1
57+
fi
58+
59+
if [ "$video_status" != "none" ]; then
60+
echo "Expecting the video status to be 'none' but instead it is: $video_status. Exiting..."
61+
exit 0
62+
fi
63+
64+
video_link="https://www.youtube.com/watch?v=${video_id}"
65+
nextsessiontitle="$(yq '.nextsessiontitle' _data/insights-videos.yaml)"
66+
nextsessionguest="$(yq '.nextsessionguest' _data/insights-videos.yaml)"
67+
68+
yq -i '
69+
.pastvideos = [
70+
{
71+
"title": "'"$nextsessiontitle"'",
72+
"date": "'"$nextsessiondate_formatted"'",
73+
"authors": "'"$nextsessionguest"'",
74+
"link": "'"$video_link"'"
75+
}
76+
] + .pastvideos
77+
' _data/insights-videos.yaml
78+
79+
echo "title=$(yq '.nextsessiontitle' _data/insights-videos.yaml)" >> "$GITHUB_OUTPUT"
80+
- name: Set next session information
81+
if: steps.archive_session.outputs.title != ''
82+
run: |
83+
yq -i 'del(.futurevideos[0])' _data/insights-videos.yaml
84+
85+
title=$(yq '.futurevideos[0].title' _data/insights-videos.yaml)
86+
guests=$(yq '.futurevideos[0].authors' _data/insights-videos.yaml)
87+
88+
date_raw=$(yq '.futurevideos[0].date' _data/insights-videos.yaml)
89+
date_iso=$(date --date="$date_raw" +"%Y-%m-%d")
90+
date=${date_iso}T13:00Z
91+
92+
yq -i '.nextsessiontitle = "'"$title"'"' _data/insights-videos.yaml
93+
yq -i '.nextsessionguest = "'"$guests"'"' _data/insights-videos.yaml
94+
yq -i '.nextsessiondate = "'"$date"'"' _data/insights-videos.yaml
95+
96+
- name: Commit and Create Pull Request
97+
if: steps.archive_session.outputs.title != ''
98+
env:
99+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
run: |
101+
# first see if the PR is already there, but just not merged yet:
102+
103+
pr_number=$(gh pr list \
104+
--repo "github.com/marko-bekhta/quarkusio.github.io" \
105+
--state open \
106+
--search "${{ steps.archive_session.outputs.title }}" \
107+
--json number \
108+
--jq '.[0].number' 2>/dev/null \
109+
-L 1)
110+
111+
if [[ -n "$pr_number" ]]; then
112+
echo "Found existing PR: #$pr_number (Title: '${{ steps.archive_session.outputs.title }}')"
113+
exit 0
114+
fi
115+
116+
# PR is not there yet so let's create one:
117+
118+
git config --local user.name "Action user"
119+
git config --global user.email "actionuser@foo"
120+
121+
branch_name="feat/update-sessions-$(date +'%Y%m%d%H%M')"
122+
git checkout -b "$branch_name"
123+
124+
git add _data/insights-videos.yaml
125+
git commit -m "[Insights sessions] move '${{ steps.archive_session.outputs.title }}' to archive"
126+
127+
# Push the new branch
128+
git push -u origin "$branch_name"
129+
130+
# Create a pull request using the GitHub CLI
131+
gh pr create --title "[Insights sessions] move '${{ steps.archive_session.outputs.title }}' to archive" \
132+
--body "Automated Quarkus Insights session update." \
133+
--base main \
134+
--head "$branch_name" \
135+
--repo "github.com/marko-bekhta/quarkusio.github.io"

0 commit comments

Comments
 (0)