Skip to content

Regenerate NuGet and Node Sources #10

Regenerate NuGet and Node Sources

Regenerate NuGet and Node Sources #10

# This workflow does 4 things:
# - Restore data from GitHub Actions cache from previous runs of this workflow.
# - Regenerate NuGet sources for ARM64 and x86_64 used to build jellyfin. (Previously also confusingly called cache.)
# - Regenerate Node sources used to build jellyfin-web. (Previously not included in this workflow.)
# - Create a Pull Request if data has changed.
#
# NOTE:
# - Why so many env blocks? https://woodruffw.github.io/zizmor/audits/#template-injection
#
name: Regenerate NuGet and Node Sources
on:
# TODO: Remove, seems to be fixed.
# Running this workflow on a schedule with the current tooling will only
# create noise and waste resources. The order of the dependencies can change
# while versions and hashes remain the same. Since this workflow now exists
# and is considered complete, a maintainer should be able to run this
# workflow on demand from the GitHub app on a mobile device when the bot
# detects a new release of Jellyfin.
schedule:
# Past releases usually happened late on Ssturday
- cron: 15 6 * * SUN
workflow_dispatch:
env:
MANIFEST: "main/org.jellyfin.JellyfinServer.yml"
PR_BRANCH: update-nuget-node
REPO_BACKEND: "jellyfin/jellyfin"
REPO_FRONTEND: "jellyfin/jellyfin-web"
SOFTWARE_NAME: "Jellyfin"
jobs:
Regenerate-NuGet-Node-Sources:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout this repository
uses: actions/checkout@v4
with:
persist-credentials: false
path: main
- name: Check if branch used for Pull Request exists
working-directory: main
run: |
if [[ -n "$(git ls-remote --heads origin "${PR_BRANCH}")" ]]; then
echo "Warning: Branch '${PR_BRANCH}' exists. Merge the Pull Request or delete the branch."
exit 1
else
echo "OK: Branch not found."
fi
env:
PR_BRANCH: ${{ env.PR_BRANCH }}
# Restores the path below contains most of the data of installed apps and runtimes.
# This can save about 1GB of downloads.
- name: Restore Flatpak apps from cache
uses: actions/cache@v4
with:
path: |
~/.local/share/flatpak
key: flatpak-cache-x86_64-${{ github.sha }}
restore-keys: |
flatpak
- name: Install flatpak and pipx package
run: |
sudo apt-get update -y
sudo apt-get install flatpak pipx -y --no-install-recommends
- name: Install yq binary, if necessary
run: |
if ! command -v "yq" > /dev/null 2>&1; then
mkdir -pv ~/.local/bin
wget --quiet https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 \
-O ~/.local/bin/yq
chmod -v +x ~/.local/bin/yq
fi
- name: Get latest ${{ env.SOFTWARE_NAME }} frontend tag
id: jq_tag_jf_fe
run: |
latest_tag=$(
curl -s "https://api.github.com/repos/${REPO_FRONTEND}/releases/latest" \
| jq -r '.tag_name'
)
echo "JQ_TAG_JF_FE=$latest_tag" >> "$GITHUB_ENV"
env:
REPO_FRONTEND: ${{ env.REPO_FRONTEND }}
- name: Get latest ${{ env.SOFTWARE_NAME }} backend tag
id: jq_tag_jf_be
run: |
latest_tag=$(
curl -s "https://api.github.com/repos/${REPO_BACKEND}/releases/latest" \
| jq -r '.tag_name'
)
echo "JQ_TAG_JF_BE=$latest_tag" >> "$GITHUB_ENV"
env:
REPO_BACKEND: ${{ env.REPO_BACKEND }}
- name: Extract environment variables from manifest
run: |
# shellcheck disable=SC2129
# Freedesktop SDK runtime rersion, example: 24.08
echo "YQ_RUNTIME_VERSION=$(yq '.runtime-version' "${MANIFEST}")" >> "$GITHUB_ENV"
# Jellyfin tag, example: 10.10.3
echo "YQ_JF_TAG=$(yq '.modules[-1].sources[2].tag' "${MANIFEST}")" >> "$GITHUB_ENV"
# DotNet SDK, example: org.freedesktop.Sdk.Extension.dotnet8
echo "YQ_DOTNETSDK=$(yq '.sdk-extensions[0]' "${MANIFEST}")" >> "$GITHUB_ENV"
# DotNet version, example: 8
YQ_DOTNETSDK="$(yq '.sdk-extensions[0]' "${MANIFEST}")"
echo "DOT_NET_VER=${YQ_DOTNETSDK##*dotnet}" >> "$GITHUB_ENV"
# Node SDK, example: org.freedesktop.Sdk.Extension.node22
echo "YQ_NODESDK=$(yq '.sdk-extensions[1]' "${MANIFEST}")" >> "$GITHUB_ENV"
# If frontend and backend tags are equal, and backend tag is not empty,
# and backend tag does not match the manifest, then there must be a new
# release.
# shellcheck disable=SC2153
if [[ "${JQ_TAG_JF_FE}" == "${JQ_TAG_JF_BE}" && -n "${JQ_TAG_JF_BE}" && "${JQ_TAG_JF_BE}" != "${YQ_JF_TAG}" ]]; then
echo "JF_TAG=${JQ_TAG_JF_BE}" >> "$GITHUB_ENV"
echo "NEW_RELEASE_DETECTED=true" >> "$GITHUB_ENV"
else
echo "JF_TAG=${YQ_JF_TAG}" >> "$GITHUB_ENV"
echo "NEW_RELEASE_DETECTED=false" >> "$GITHUB_ENV"
fi
env:
JQ_TAG_JF_FE: ${{ env.JQ_TAG_JF_FE }}
JQ_TAG_JF_BE: ${{ env.JQ_TAG_JF_BE }}
MANIFEST: ${{ env.MANIFEST }}
- name: Install Flatpak Builder, Freedesktop SDK, DotNet and Node
run: |
flatpak remote-add --user --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak update --user --noninteractive -y
flatpak install --user flathub "org.flatpak.Builder" --noninteractive -y
flatpak install --user flathub "org.freedesktop.Sdk//${YQ_RUNTIME_VERSION}" --noninteractive -y
flatpak install --user flathub "${YQ_DOTNETSDK}//${YQ_RUNTIME_VERSION}" --noninteractive -y
flatpak install --user flathub "${YQ_NODESDK}//${YQ_RUNTIME_VERSION}" --noninteractive -y
env:
DOT_NET_VER: ${{ env.DOT_NET_VER }}
YQ_DOTNETSDK: ${{ env.YQ_DOTNETSDK }}
YQ_NODESDK: ${{ env.YQ_NODESDK }}
YQ_RUNTIME_VERSION: ${{ env.YQ_RUNTIME_VERSION }}
- name: Checkout Flatpak Builder Tools
uses: actions/checkout@v4
with:
persist-credentials: false
repository: flatpak/flatpak-builder-tools
path: flatpak-builder-tools
- name: Install flatpak-node-generator with pipx
run: |
pipx install "./flatpak-builder-tools/node/"
- name: Checkout jellyfin
uses: actions/checkout@v4
with:
persist-credentials: false
repository: jellyfin/jellyfin
path: jellyfin
ref: ${{ env.JF_TAG }}
- name: Checkout jellyfin-web
uses: actions/checkout@v4
with:
persist-credentials: false
repository: jellyfin/jellyfin-web
path: jellyfin-web
ref: ${{ env.JF_TAG }}
- name: Generate sources for NuGet x64 used by jellyfin
run: |
./flatpak-builder-tools/dotnet/flatpak-dotnet-generator.py \
--dotnet "${DOT_NET_VER}" --freedesktop "${YQ_RUNTIME_VERSION}" --runtime=linux-x64 \
"main/nuget-generated-sources-x64.json" \
"jellyfin/Jellyfin.Server/Jellyfin.Server.csproj"
env:
DOT_NET_VER: ${{ env.DOT_NET_VER }}
YQ_RUNTIME_VERSION: ${{ env.YQ_RUNTIME_VERSION }}
- name: Generate sources for NuGet arm64 used by jellyfin
run: |
./flatpak-builder-tools/dotnet/flatpak-dotnet-generator.py \
--dotnet "${DOT_NET_VER}" --freedesktop "${YQ_RUNTIME_VERSION}" --runtime=linux-arm64 \
"main/nuget-generated-sources-arm64.json" \
"jellyfin/Jellyfin.Server/Jellyfin.Server.csproj"
env:
DOT_NET_VER: ${{ env.DOT_NET_VER }}
YQ_RUNTIME_VERSION: ${{ env.YQ_RUNTIME_VERSION }}
- name: Generate sources for Node used by jellyfin-web
run: |
flatpak-node-generator \
-o "main/npm-generated-sources.json" npm "jellyfin-web/package-lock.json"
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: latest
- name: Install Prettier
run: |
npm install -g prettier
- name: Reformat JSON files
run: npx prettier --write "main/"*".json"
- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
path: main
title: Regenerate NuGet and Node Sources ${{ env.JF_TAG }}
commit-message: Regenerate NuGet and Node Sources ${{ env.JF_TAG }}
branch: ${{ env.PR_BRANCH }}
delete-branch: true