update-nightly #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: update-nightly | |
on: | |
workflow_dispatch: | |
jobs: | |
get-releases: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Run Bash Script to Get Pre-Releases | |
id: get_pre_releases | |
run: | | |
TOKEN=${{ secrets.GITHUB_TOKEN }} | |
response=$(curl -L \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/donderjoekel/Sonarr/releases) | |
# Extract the first pre-release from the JSON response | |
pre_release=$(echo $response | jq -r '[.[] | select(.prerelease == true)][0]') | |
pre_release_tag=$(echo $pre_release | jq -r '.tag_name') | |
pre_release_name=$(echo $pre_release | jq -r '.name') | |
pre_release_url=$(echo $pre_release | jq -r '.html_url') | |
echo "pre_release_tag=$pre_release_tag" >> $GITHUB_ENV | |
echo "pre_release_name=$pre_release_name" >> $GITHUB_ENV | |
echo "pre_release_url=$pre_release_url" >> $GITHUB_ENV | |
# Iterate over assets and extract browser_download_url | |
for url in $(echo $pre_release | jq -r '.assets[].browser_download_url'); do | |
# Use regex to extract the desired part of the URL | |
if [[ "$url" =~ Sonarr\.develop\.[0-9.]+\.([a-zA-Z0-9_-]+)\. ]]; then | |
key=$(echo "${BASH_REMATCH[1]}") | |
key=$(echo $key | tr '-' '_') | |
echo "${key}_download_url=$url" >> $GITHUB_ENV | |
else | |
echo "Unable to extract key" | |
fi | |
done | |
- name: Update VERSION.json | |
run: | | |
linux_musl_x64_url="${{ env.linux_musl_x64_download_url }}" | |
linux_musl_arm64_url="${{ env.linux_musl_arm64_download_url }}" | |
version="${{ env.pre_release_name }}" | |
# Load the VERSION.json file | |
version_json=$(cat VERSION.json) | |
# Update the properties in VERSION.json | |
updated_version_json=$(echo "$version_json" | jq \ | |
--arg linux_musl_x64_url "$linux_musl_x64_url" \ | |
--arg linux_musl_arm64_url "$linux_musl_arm64_url" \ | |
--arg version "$version" \ | |
'.amd64_url = $linux_musl_x64_url | .arm64_url = $linux_musl_arm64_url | .version = $version') | |
# Save the updated JSON back to VERSION.json | |
echo "$updated_version_json" > VERSION.json | |
- name: Commit and Push Changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add VERSION.json | |
git commit -m "Update VERSION.json" | |
git push origin HEAD:${{ github.ref }} |