Skip to content

Commit a8fa842

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

File tree

1 file changed

+121
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)