From ada69932f55130f90b7f79321e09aac3afc735b1 Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Sat, 23 Sep 2023 11:22:33 +0200 Subject: [PATCH] Migrate publishing to GitHub actions --- .ci/azure-pipelines.yml | 173 --------------------------------- .github/workflows/publish.yaml | 142 +++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 173 deletions(-) delete mode 100644 .ci/azure-pipelines.yml create mode 100644 .github/workflows/publish.yaml diff --git a/.ci/azure-pipelines.yml b/.ci/azure-pipelines.yml deleted file mode 100644 index 465e2aac..00000000 --- a/.ci/azure-pipelines.yml +++ /dev/null @@ -1,173 +0,0 @@ -trigger: - batch: true - branches: - include: - - '*' - tags: - include: - - '*' -pr: - branches: - include: - - '*' - -jobs: - - job: Build - displayName: 'Build' - - strategy: - matrix: - Development: - BuildConfiguration: development - Production: - BuildConfiguration: production - - pool: - vmImage: 'ubuntu-latest' - - steps: - - task: NodeTool@0 - displayName: 'Install Node' - inputs: - versionSpec: '20.x' - - - task: Cache@2 - displayName: 'Check Cache' - inputs: - key: 'npm | package-lock.json' - path: 'node_modules' - cacheHitVar: CACHE_RESTORED - - - script: 'npm ci --no-audit' - displayName: 'Install Dependencies' - condition: ne(variables.CACHE_RESTORED, 'true') - - - script: | - package_json="$(cat package.json | jq '.version = .version + "-'$BUILD_BUILDNUMBER'"')" - echo "$package_json" > package.json - displayName: 'Update version in package.json' - - - script: 'npm run build:development' - displayName: 'Build Development' - condition: eq(variables['BuildConfiguration'], 'development') - - - script: 'npm run build:production' - displayName: 'Build Bundle' - condition: eq(variables['BuildConfiguration'], 'production') - - - script: 'test -d dist' - displayName: 'Check Build' - - - script: 'mv dist jellyfin-chromecast' - displayName: 'Rename Directory' - - - task: ArchiveFiles@2 - displayName: 'Archive Directory' - inputs: - rootFolderOrFile: 'jellyfin-chromecast' - includeRootFolder: true - archiveFile: 'jellyfin-chromecast-$(BuildConfiguration)' - - - task: PublishPipelineArtifact@1 - displayName: 'Publish Release' - inputs: - targetPath: '$(Build.SourcesDirectory)/jellyfin-chromecast-$(BuildConfiguration).zip' - artifactName: 'jellyfin-chromecast-$(BuildConfiguration)' - - - job: Publish - displayName: 'Publish' - - dependsOn: Build - condition: or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/tags')) - - strategy: - matrix: - Development: - BuildConfiguration: development - Production: - BuildConfiguration: production - - pool: - vmImage: 'ubuntu-latest' - - steps: - - script: 'echo "##vso[task.setvariable variable=TAG]$(git describe --tags)"' - displayName: 'Set Tag Variable' - - - task: DownloadPipelineArtifact@2 - displayName: 'Download Artifact' - inputs: - source: 'current' - artifact: 'jellyfin-chromecast-$(BuildConfiguration)' - path: '$(System.ArtifactsDirectory)' - runVersion: 'latest' - - - task: GithubRelease@0 - displayName: 'GitHub Upload' - condition: startsWith(variables['Build.SourceBranch'], 'refs/tags') - inputs: - gitHubConnection: Jellyfin Release Download - repositoryName: jellyfin/jellyfin-chromecast - assets: '$(System.ArtifactsDirectory)/*.zip' - action: 'edit' - assetUploadMode: 'replace' - tag: '$(TAG)' - - - task: CopyFilesOverSSH@0 - displayName: 'Upload to Repository' - inputs: - sshEndpoint: repository - sourceFolder: '$(System.ArtifactsDirectory)' - contents: '**' - targetFolder: '/srv/repository/releases/client/chromecast/versions/$(TAG)' - - - task: SSH@0 - displayName: 'Symlink Latest Version' - inputs: - sshEndpoint: repository - runOptions: 'inline' - inline: 'cd /srv/repository/releases/client/chromecast && rm -rf *.zip && ln -s versions/$(TAG)/jellyfin-chromecast-$(BuildConfiguration)-$(TAG).zip .' - - - job: Production - displayName: 'Production' - - dependsOn: Build - condition: or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/tags')) - - pool: - vmImage: 'ubuntu-latest' - - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download Artifact' - inputs: - source: 'current' - artifact: 'jellyfin-chromecast-production' - path: '$(System.ArtifactsDirectory)' - runVersion: 'latest' - - - task: ExtractFiles@1 - displayName: 'Extract Source' - inputs: - archiveFilePatterns: '$(System.ArtifactsDirectory)/*.zip' - destinationFolder: '$(System.ArtifactsDirectory)/artifact' - cleanDestinationFolder: true - - - task: CopyFilesOverSSH@0 - displayName: 'Update Nightly' - inputs: - sshEndpoint: chromecast - sourceFolder: '$(System.ArtifactsDirectory)/artifact/jellyfin-chromecast' - cleanTargetFolder: true - contents: '**' - targetFolder: '/srv/chromecast/nightly' - - - task: CopyFilesOverSSH@0 - displayName: 'Update Stable' - condition: startsWith(variables['Build.SourceBranch'], 'refs/tags') - inputs: - sshEndpoint: chromecast - sourceFolder: '$(System.ArtifactsDirectory)/artifact/jellyfin-chromecast' - cleanTargetFolder: true - contents: '**' - targetFolder: '/srv/chromecast/stable' diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..889093a1 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,142 @@ +name: Publish + +on: + push: + branches: + - master + tags: + - '*' + pull_request: + branches: + - master + +jobs: + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + flavor: [development, production] + + steps: + - name: Checkout + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + + - name: Setup node env + uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1 + with: + node-version: 20 + + - name: Install dependencies + run: npm ci --no-audit + + - name: Update version in package.json + run: | + PACKAGE_JSON=$(jq --indent 4 ".version += \"-$GITHUB_SHA\"" package.json) + echo $PACKAGE_JSON > package.json + + - name: Build development + if: ${{ matrix.flavor == 'development' }} + run: npm run build:development + + - name: Build production + if: ${{ matrix.flavor == 'production' }} + run: npm run build:production + + - name: Prepare artifacts + run: | + test -d dist + mv dist jellyfin-chromecast + zip -r "jellyfin-chromecast-${{ matrix.flavor }}.zip" "jellyfin-chromecast" + + - name: Upload artifacts + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + with: + name: jellyfin-chromecast-${{ matrix.flavor }} + path: jellyfin-chromecast-${{ matrix.flavor }}.zip + if-no-files-found: error + + publish: + name: Publish + runs-on: ubuntu-latest + if: ${{ contains(github.repository_owner, 'jellyfin') && (github.ref == 'refs/head/master' || startsWith(github.ref, 'refs/tags')) }} + needs: [build] + strategy: + matrix: + flavor: [development, production] + + steps: + - name: Set JELLYFIN_VERSION + run: echo "JELLYFIN_VERSION=$(echo ${GITHUB_REF#refs/tags/v} | tr / -)" >> $GITHUB_ENV + + - name: Download Artifact + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: jellyfin-chromecast-${{ matrix.flavor }} + + - name: Upload release archive to GitHub release + if: ${{ startsWith(github.ref, 'refs/tags') }} + uses: alexellis/upload-assets@259de5111cb56966d046ced998941e93f91d2c93 # tag=0.4.0 + env: + GITHUB_TOKEN: ${{ secrets.JF_BOT_TOKEN }} + with: + asset_paths: '["jellyfin-chromecast-${{ matrix.flavor }}.zip"]' + + - name: Upload release archive to repo.jellyfin.org + uses: burnett01/rsync-deployments@45d84ad5f6c174f3e0ffc50e9060a9666d09c16e # 6.0.0 + with: + switches: -vrptz + path: jellyfin-chromecast-${{ matrix.flavor }}.zip + remote_path: /srv/repository/releases/client/chromecast/versions/$({{ env.JELLYFIN_VERSION }}) + remote_host: ${{ secrets.DEPLOY_HOST }} + remote_user: ${{ secrets.DEPLOY_USER }} + remote_key: ${{ secrets.DEPLOY_KEY }} + + - name: Update repo.jellyfin.org symlinks + uses: appleboy/ssh-action@55dabf81b49d4120609345970c91507e2d734799 # v1.0.0 + with: + host: ${{ secrets.DEPLOY_HOST }} + username: ${{ secrets.DEPLOY_USER }} + key: ${{ secrets.DEPLOY_KEY }} + envs: JELLYFIN_VERSION + script_stop: true + script: | + cd /srv/repository/releases/client/chromecast; + rm -rf *.zip; + ln -s versions/${JELLYFIN_VERSION}/jellyfin-chromecast-${{ matrix.flavor }}-${JELLYFIN_VERSION}.zip .; + + deploy: + name: Deploy + runs-on: ubuntu-latest + if: ${{ contains(github.repository_owner, 'jellyfin') && (github.ref == 'refs/head/master' || startsWith(github.ref, 'refs/tags')) }} + needs: [build] + + steps: + - name: Download Artifact + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: jellyfin-chromecast-production + + - name: Unzip artifact + run: unzip jellyfin-chromecast-production.zip -d jellyfin-chromecast + + - name: Deploy to apps1.jellyfin.org/chromecast/nightly + uses: burnett01/rsync-deployments@45d84ad5f6c174f3e0ffc50e9060a9666d09c16e # 6.0.0 + with: + switches: -vrptz + path: jellyfin-chromecast + remote_path: /srv/chromecast/nightly + remote_host: ${{ secrets.DEPLOY_CC_HOST }} + remote_user: ${{ secrets.DEPLOY_CC_USER }} + remote_key: ${{ secrets.DEPLOY_CC_KEY }} + + - name: Deploy to apps1.jellyfin.org/chromecast/stable + if: ${{ startsWith(github.ref, 'refs/tags') }} + uses: burnett01/rsync-deployments@45d84ad5f6c174f3e0ffc50e9060a9666d09c16e # 6.0.0 + with: + switches: -vrptz + path: jellyfin-chromecast + remote_path: /srv/chromecast/stable + remote_host: ${{ secrets.DEPLOY_CC_HOST }} + remote_user: ${{ secrets.DEPLOY_CC_USER }} + remote_key: ${{ secrets.DEPLOY_CC_KEY }}