Skip to content

Commit 0b3e1f7

Browse files
committed
Add a wordflow to update Quarkus Insights videos
1 parent ae4e14d commit 0b3e1f7

File tree

1 file changed

+119
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)