ci: make github actions reusable

This commit is contained in:
Kilian von Pflugk 2024-10-18 12:39:56 +02:00
parent 7e65ad1685
commit f6c8fca28f
5 changed files with 77 additions and 17 deletions

View File

@ -2,7 +2,8 @@ name: "Build Plugin"
on: on:
push: push:
branches: ["master"] branches:
- '*'
paths-ignore: paths-ignore:
- "**/README.md" - "**/README.md"
- ".github/ISSUE_TEMPLATE/**" - ".github/ISSUE_TEMPLATE/**"
@ -10,7 +11,8 @@ on:
- "images/**" - "images/**"
- "manifest.json" - "manifest.json"
pull_request: pull_request:
branches: ["master"] branches:
- '*'
paths-ignore: paths-ignore:
- "**/README.md" - "**/README.md"
- ".github/ISSUE_TEMPLATE/**" - ".github/ISSUE_TEMPLATE/**"
@ -39,6 +41,22 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Read version from VERSION.txt
id: read-version
run: |
MAIN_VERSION=$(cat VERSION.txt)
echo "MAIN_VERSION=${MAIN_VERSION}"
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
- name: Check for BETA file
id: check-beta
run: |
if [ -f "BETA" ]; then
echo "IS_BETA=true" >> $GITHUB_ENV
else
echo "IS_BETA=false" >> $GITHUB_ENV
fi
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v4
with: with:
@ -55,12 +73,17 @@ jobs:
npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -c -m npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -c -m
npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -c -m npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -c -m
- name: Restore dependencies - name: Restore Beta dependencies
if: ${{env.IS_BETA == 'true' }}
run: | run: |
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name jellyfin-pre "https://nuget.pkg.github.com/jellyfin/index.json" dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name jellyfin-pre "https://nuget.pkg.github.com/jellyfin/index.json"
dotnet tool install --global dotnet-outdated-tool dotnet tool install --global dotnet-outdated-tool
dotnet outdated -pre Always -u -inc Jellyfin dotnet outdated -pre Always -u -inc Jellyfin
- name: Restore dependencies
if: ${{env.IS_BETA == 'false' }}
run: dotnet restore
- name: Embed version info - name: Embed version info
run: | run: |
GITHUB_SHA=${{ github.sha }} GITHUB_SHA=${{ github.sha }}
@ -98,7 +121,7 @@ jobs:
- name: Create/replace the preview release and upload artifacts - name: Create/replace the preview release and upload artifacts
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
run: | run: |
gh release delete '10.10/preview' --cleanup-tag --yes || true gh release delete "${{ env.MAIN_VERSION }}/preview" --cleanup-tag --yes || true
gh release create '10.10/preview' "intro-skipper-${{ env.GIT_HASH }}.zip" --prerelease --title "intro-skipper-${{ env.GIT_HASH }}" --notes "This is a prerelease version." gh release create "${{ env.MAIN_VERSION }}/preview" "intro-skipper-${{ env.GIT_HASH }}.zip" --prerelease --title "intro-skipper-${{ env.GIT_HASH }}" --notes "This is a prerelease version." --target ${{ env.MAIN_VERSION }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -2,7 +2,8 @@ name: "CodeQL"
on: on:
push: push:
branches: [master] branches:
- '*'
paths-ignore: paths-ignore:
- "**/README.md" - "**/README.md"
- ".github/ISSUE_TEMPLATE/**" - ".github/ISSUE_TEMPLATE/**"
@ -10,7 +11,8 @@ on:
- "images/**" - "images/**"
- "manifest.json" - "manifest.json"
pull_request: pull_request:
branches: [master] branches:
- '*'
paths-ignore: paths-ignore:
- "**/README.md" - "**/README.md"
- ".github/ISSUE_TEMPLATE/**" - ".github/ISSUE_TEMPLATE/**"
@ -36,25 +38,39 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Check for BETA file
id: check-beta
run: |
if [ -f "BETA" ]; then
echo "IS_BETA=true" >> $GITHUB_ENV
else
echo "IS_BETA=false" >> $GITHUB_ENV
fi
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v4
with: with:
dotnet-version: 8.0.x dotnet-version: 8.0.x
- name: Install dependencies - name: Restore Beta dependencies
if: ${{env.IS_BETA == 'true' }}
run: | run: |
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name jellyfin-pre "https://nuget.pkg.github.com/jellyfin/index.json" dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name jellyfin-pre "https://nuget.pkg.github.com/jellyfin/index.json"
dotnet tool install --global dotnet-outdated-tool dotnet tool install --global dotnet-outdated-tool
dotnet outdated -pre Always -u -inc Jellyfin dotnet outdated -pre Always -u -inc Jellyfin
- name: Restore dependencies
if: ${{env.IS_BETA == 'false' }}
run: dotnet restore
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13 uses: github/codeql-action/init@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # v3.26.11
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
queries: +security-extended queries: +security-extended
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13 uses: github/codeql-action/autobuild@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # v3.26.11
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13 uses: github/codeql-action/analyze@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # v3.26.11

View File

@ -14,6 +14,22 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Read version from VERSION.txt
id: read-version
run: |
MAIN_VERSION=$(cat VERSION.txt)
echo "MAIN_VERSION=${MAIN_VERSION}"
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
- name: Check for BETA file
id: check-beta
run: |
if [ -f "BETA" ]; then
echo "IS_BETA=true" >> $GITHUB_ENV
else
echo "IS_BETA=false" >> $GITHUB_ENV
fi
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v4
with: with:
@ -30,12 +46,17 @@ jobs:
npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -c -m npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/inject.js -c -m
npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -c -m npx terser ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -c -m
- name: Restore dependencies - name: Restore Beta dependencies
if: ${{env.IS_BETA == 'true' }}
run: | run: |
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name jellyfin-pre "https://nuget.pkg.github.com/jellyfin/index.json" dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name jellyfin-pre "https://nuget.pkg.github.com/jellyfin/index.json"
dotnet tool install --global dotnet-outdated-tool dotnet tool install --global dotnet-outdated-tool
dotnet outdated -pre Always -u -inc Jellyfin dotnet outdated -pre Always -u -inc Jellyfin
- name: Restore Beta
if: ${{env.IS_BETA == 'false' }}
run: dotnet restore
- name: Run update version - name: Run update version
uses: intro-skipper/intro-skipper-action-ts@main uses: intro-skipper/intro-skipper-action-ts@main
with: with:
@ -54,13 +75,13 @@ jobs:
- name: Remove old release if exits - name: Remove old release if exits
if: ${{ github.repository == 'intro-skipper/intro-skipper-test' }} if: ${{ github.repository == 'intro-skipper/intro-skipper-test' }}
run: gh release delete "10.10/v${{ env.NEW_FILE_VERSION }}" --cleanup-tag --yes || true run: gh release delete "${{ env.MAIN_VERSION }}/v${{ env.NEW_FILE_VERSION }}" --cleanup-tag --yes || true
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create new release with tag - name: Create new release with tag
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
run: gh release create "10.10/v${{ env.NEW_FILE_VERSION }}" "intro-skipper-v${{ env.NEW_FILE_VERSION }}.zip" --title "v${{ env.NEW_FILE_VERSION }}" --latest --generate-notes run: gh release create "${{ env.MAIN_VERSION }}/v${{ env.NEW_FILE_VERSION }}" "intro-skipper-v${{ env.NEW_FILE_VERSION }}.zip" --title "v${{ env.NEW_FILE_VERSION }}" --latest --generate-notes --target ${{ env.MAIN_VERSION }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@ -70,15 +91,14 @@ jobs:
task-type: "updateManifest" task-type: "updateManifest"
env: env:
GITHUB_REPO_VISIBILITY: ${{ github.event.repository.visibility }} GITHUB_REPO_VISIBILITY: ${{ github.event.repository.visibility }}
CURRENT_VERSION: "10.10.0" MAIN_VERSION: ${{ env.MAIN_VERSION }}
MAIN_VERSION: "10.10"
- name: Deploy to Cloudflare KV - name: Deploy to Cloudflare KV
uses: cloudflare/wrangler-action@v3 uses: cloudflare/wrangler-action@v3
with: with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: kv key put --namespace-id=${{ github.repository == 'intro-skipper/intro-skipper-test' && '49c07e5b68074443b940de893d58a997' || '61215c51799a4de59f0a33a8b7aecb0e' }} "10.10" --path=manifest.json command: kv key put --namespace-id=${{ github.repository == 'intro-skipper/intro-skipper-test' && '49c07e5b68074443b940de893d58a997' || '61215c51799a4de59f0a33a8b7aecb0e' }} ${{ env.MAIN_VERSION }} --path=manifest.json
- name: Commit changes - name: Commit changes
if: success() if: success()

0
BETA Normal file
View File

1
VERSION.txt Normal file
View File

@ -0,0 +1 @@
10.10