Skip to content

Commit 23b6e99

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

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Update Insights Sessions archive/upcoming
2+
3+
on:
4+
schedule:
5+
- cron: '0 * * * *'
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: Install yq (for yml manipulation)
20+
run: sudo apt-get update && sudo apt-get install -y yq
21+
22+
- name: Archive current session
23+
id: archive_session
24+
env:
25+
YOUTUBE_API_KEY: ${{ secrets.INSIGHTS_YOUTUBE_API_KEY }}
26+
YOUTUBE_CHANNEL_ID: ${{ secrets.INSIGHTS_YOUTUBE_CHANNEL_ID }}
27+
run: |
28+
today=$(date +"%B %d, %Y")
29+
30+
nextsessiondate=$(yq -r '.nextsessiondate' _data/insights-videos.yaml)
31+
nextsessiondate_formatted=$(date --date=$nextsessiondate +"%B %d, %Y")
32+
33+
if [ "$today" != "$nextsessiondate_formatted" ]; then
34+
echo "Next session date ($nextsessiondate_formatted) does not match today's date ($today). Skipping workflow run."
35+
exit 0
36+
fi
37+
38+
current_episode=$(yq -r '.nextsessiontitle | sub(".* #([0-9]+):.*"; "${1}")' _data/insights-videos.yaml)
39+
40+
youtube_response=$(curl -s --fail \
41+
-H "X-goog-api-key: ${YOUTUBE_API_KEY}" \
42+
"https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${YOUTUBE_CHANNEL_ID}&q=%23${current_episode}&type=video")
43+
44+
video_id=$(echo $youtube_response | jq -r '.items[0].id.videoId')
45+
video_status=$(echo $youtube_response | jq -r '.items[0].snippet.liveBroadcastContent')
46+
video_title=$(echo $youtube_response | jq -r '.items[0].snippet.title')
47+
48+
# Check if a video ID was found
49+
if [ -z "$video_id" ] || [ "$video_id" == "null" ]; then
50+
echo "Could not find the YouTube video for episode #$current_episode. Assuming it's not there yet. Exiting..."
51+
exit 0
52+
fi
53+
54+
if [[ "$video_title" == *"#$current_episode"* ]]; then
55+
echo "The video title contains the required episode number: '#$current_episode'"
56+
else
57+
echo "The video title does NOT contain the required episode number: '#$current_episode'. Exiting..."
58+
exit 1
59+
fi
60+
61+
if [ "$video_status" != "none" ]; then
62+
echo "Expecting the video status to be 'none' but instead it is: $video_status. Exiting..."
63+
exit 0
64+
fi
65+
66+
video_link="https://www.youtube.com/watch?v=${video_id}"
67+
nextsessiontitle="$(yq '.nextsessiontitle' _data/insights-videos.yaml)"
68+
nextsessionguest="$(yq '.nextsessionguest' _data/insights-videos.yaml)"
69+
70+
yq -i '
71+
.pastvideos += [
72+
{
73+
"title": "'"$nextsessiontitle"'",
74+
"date": "'"$nextsessiondate_formatted"'",
75+
"authors": "'"$nextsessionguest"'",
76+
"link:": "'"$video_link"'"
77+
}
78+
]
79+
' _data/insights-videos.yaml
80+
81+
echo "title=$(yq '.nextsessiontitle' _data/insights-videos.yaml)" >> "$GITHUB_OUTPUT"
82+
- name: Set next session information
83+
if: steps.archive_session.outputs.title != ''
84+
run: |
85+
yq -i 'del(.futurevideos[0])' _data/insights-videos.yaml
86+
87+
title=$(yq '.futurevideos[0].title' _data/insights-videos.yaml)
88+
guests=$(yq '.futurevideos[0].authors' _data/insights-videos.yaml)
89+
90+
date_raw=$(yq '.futurevideos[0].date' _data/insights-videos.yaml)
91+
date_iso=$(date --date="$date_raw" +"%Y-%m-%d")
92+
date=${date_iso}T13:00Z
93+
94+
yq -i '.nextsessiontitle = "'"$title"'"' _data/insights-videos.yaml
95+
yq -i '.nextsessionguest = "'"$guests"'"' _data/insights-videos.yaml
96+
yq -i '.nextsessiondate = "'"$date"'"' _data/insights-videos.yaml
97+
98+
- name: Commit and Create Pull Request
99+
if: steps.archive_session.outputs.title != ''
100+
env:
101+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
run: |
103+
branch_name="feat/update-sessions-$(date +'%Y%m%d%H%M')"
104+
git checkout -b "$branch_name"
105+
106+
git add _data/insights-videos.yaml
107+
git commit -m "[Insights sessions] move '${{ steps.archive_session.outputs.title }}' to archive"
108+
109+
# Push the new branch
110+
git push -u origin "$branch_name"
111+
112+
# Create a pull request using the GitHub CLI
113+
gh pr create --title "[Insights sessions] move '${{ steps.archive_session.outputs.title }}' to archive" \
114+
--body "Automated Quarkus Insights session update." \
115+
--base main \
116+
--head "$branch_name" \
117+
--repo "github.com/marko-bekhta/quarkusio.github.io"

0 commit comments

Comments
 (0)