From f6c8fca28f83e6d07046771c7382c2be5af81cb7 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Fri, 18 Oct 2024 12:39:56 +0200 Subject: [PATCH] ci: make github actions reusable --- .github/workflows/build.yml | 33 ++++++++++++++++++++++++++++----- .github/workflows/codeql.yml | 28 ++++++++++++++++++++++------ .github/workflows/release.yml | 32 ++++++++++++++++++++++++++------ BETA | 0 VERSION.txt | 1 + 5 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 BETA create mode 100644 VERSION.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7991cd1..c1457ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,8 @@ name: "Build Plugin" on: push: - branches: ["master"] + branches: + - '*' paths-ignore: - "**/README.md" - ".github/ISSUE_TEMPLATE/**" @@ -10,7 +11,8 @@ on: - "images/**" - "manifest.json" pull_request: - branches: ["master"] + branches: + - '*' paths-ignore: - "**/README.md" - ".github/ISSUE_TEMPLATE/**" @@ -39,6 +41,22 @@ jobs: - 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 uses: actions/setup-dotnet@v4 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/visualizer.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -c -m - - name: Restore dependencies + - name: Restore Beta dependencies + if: ${{env.IS_BETA == 'true' }} 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 tool install --global dotnet-outdated-tool dotnet outdated -pre Always -u -inc Jellyfin + - name: Restore dependencies + if: ${{env.IS_BETA == 'false' }} + run: dotnet restore + - name: Embed version info run: | GITHUB_SHA=${{ github.sha }} @@ -98,7 +121,7 @@ jobs: - name: Create/replace the preview release and upload artifacts if: github.event_name != 'pull_request' run: | - gh release delete '10.10/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 delete "${{ env.MAIN_VERSION }}/preview" --cleanup-tag --yes || true + 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: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 2f931b3..fb41dc3 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,7 +2,8 @@ name: "CodeQL" on: push: - branches: [master] + branches: + - '*' paths-ignore: - "**/README.md" - ".github/ISSUE_TEMPLATE/**" @@ -10,7 +11,8 @@ on: - "images/**" - "manifest.json" pull_request: - branches: [master] + branches: + - '*' paths-ignore: - "**/README.md" - ".github/ISSUE_TEMPLATE/**" @@ -36,25 +38,39 @@ jobs: steps: - 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 uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - - name: Install dependencies + - name: Restore Beta dependencies + if: ${{env.IS_BETA == 'true' }} 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 tool install --global dotnet-outdated-tool dotnet outdated -pre Always -u -inc Jellyfin + - name: Restore dependencies + if: ${{env.IS_BETA == 'false' }} + run: dotnet restore + - name: Initialize CodeQL - uses: github/codeql-action/init@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13 + uses: github/codeql-action/init@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # v3.26.11 with: languages: ${{ matrix.language }} queries: +security-extended - name: Autobuild - uses: github/codeql-action/autobuild@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13 + uses: github/codeql-action/autobuild@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # v3.26.11 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@f779452ac5af1c261dce0346a8f964149f49322b # v3.26.13 + uses: github/codeql-action/analyze@6db8d6351fd0be61f9ed8ebd12ccd35dcec51fea # v3.26.11 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3a0631b..134c91c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,22 @@ jobs: steps: - 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 uses: actions/setup-dotnet@v4 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/visualizer.js -o ConfusedPolarBear.Plugin.IntroSkipper/Configuration/visualizer.js -c -m - - name: Restore dependencies + - name: Restore Beta dependencies + if: ${{env.IS_BETA == 'true' }} 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 tool install --global dotnet-outdated-tool dotnet outdated -pre Always -u -inc Jellyfin + - name: Restore Beta + if: ${{env.IS_BETA == 'false' }} + run: dotnet restore + - name: Run update version uses: intro-skipper/intro-skipper-action-ts@main with: @@ -54,13 +75,13 @@ jobs: - name: Remove old release if exits 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: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create new release with tag 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: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -70,15 +91,14 @@ jobs: task-type: "updateManifest" env: GITHUB_REPO_VISIBILITY: ${{ github.event.repository.visibility }} - CURRENT_VERSION: "10.10.0" - MAIN_VERSION: "10.10" + MAIN_VERSION: ${{ env.MAIN_VERSION }} - name: Deploy to Cloudflare KV uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} 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 if: success() diff --git a/BETA b/BETA new file mode 100644 index 0000000..e69de29 diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..121281c --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +10.10 \ No newline at end of file