From 08e90eacf661bcd39530f7c958babc980e7cb7f1 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Thu, 26 Sep 2024 15:51:12 +0100 Subject: [PATCH] Pull in upload action --- .github/actions/dist-upload/action.yml | 69 ++++++++++++++++++++++++++ .github/workflows/ci.yml | 37 ++++++++++---- 2 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 .github/actions/dist-upload/action.yml diff --git a/.github/actions/dist-upload/action.yml b/.github/actions/dist-upload/action.yml new file mode 100644 index 000000000..5e29bb098 --- /dev/null +++ b/.github/actions/dist-upload/action.yml @@ -0,0 +1,69 @@ +name: "Distribute upload" +description: "Uploads the package from the dist dir to GitHub artifacts or Google Drive" +inputs: + use-github: + description: "Whether to upload to GitHub artifacts" + required: true + + use-gdrive: + description: "Whether to upload to Google Drive" + required: true + + github-target-filename: + description: "Filename to upload (GitHub artifacts)" + required: true + + gdrive-target-base-dir: + description: "Base directory to upload (Google Drive)" + required: true + + gdrive-secret-key: + description: "Google Drive secret key" + required: true + + gdrive-parent-folder-id: + description: "Google Drive parent folder ID" + required: true + + package-version: + description: "Package version appended to the Google Drive dir" + required: true + +runs: + using: "composite" + + steps: + - if: ${{ inputs.use_gdrive == inputs.use-github }} + run: | + echo "Either 'use-github' or 'use_gdrive' must be true (and not both)" + exit 1 + shell: bash + + - if: ${{ inputs.use_gdrive == 'true' && !inputs.package-version }} + run: | + echo "Input 'package-version' is required when uploading to Google Drive" + exit 1 + shell: bash + + - if: ${{ inputs.use_gdrive == 'true' }} + run: | + SHORT_VERSION=$(echo "${{ inputs.package-version }}" | cut -d'-' -f1 | cut -d'+' -f1) + echo "SHORT_VERSION=$SHORT_VERSION" >> $GITHUB_ENV + shell: bash + + - name: Upload to GitHub + if: ${{ inputs.use-github == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.github-target-filename }} + path: ./dist + retention-days: 3 + + - name: Upload to Google Drive + if: ${{ inputs.use_gdrive == 'true' }} + uses: symless/gdrive-upload@target-glob + with: + credentials: ${{ inputs.gdrive-secret-key }} + target: "./dist/*" + parent_folder_id: ${{ inputs.gdrive-parent-folder-id }} + child_folder: Packages/${{ inputs.gdrive-target-base-dir }}/${{ env.SHORT_VERSION }}/${{ inputs.package-version }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dd88c4d7..2a4a4f274 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,13 @@ on: env: GIT_SHA: ${{ github.sha }} - PACKAGE_BUILD: ${{ !github.event.pull_request.draft }} - PACKAGE_UPLOAD: ${{ !github.event.pull_request.draft }} SYNERGY_PRODUCT_NAME: ${{ vars.SYNERGY_PRODUCT_NAME }} SYNERGY_PACKAGE_PREFIX: ${{ vars.SYNERGY_PACKAGE_PREFIX }} + SYNERGY_ENABLE_ACTIVATION: ${{ vars.SYNERGY_ENABLE_ACTIVATION }} + PACKAGE_BUILD: ${{ !github.event.pull_request.draft }} + PACKAGE_UPLOAD: ${{ !github.event.pull_request.draft }} + UPLOAD_TO_GITHUB: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }} + UPLOAD_TO_GDRIVE: ${{ github.event_name != 'pull_request' }} jobs: # Quality gate to allow PR merge, used in the branch protection rules. @@ -116,11 +119,15 @@ jobs: - name: Upload if: ${{ env.PACKAGE_UPLOAD == 'true' }} - uses: ./deskflow/.github/actions/dist-upload + uses: ./.github/actions/dist-upload with: - use-github: true + use-github: ${{ env.UPLOAD_TO_GITHUB }} + use-gdrive: ${{ env.UPLOAD_TO_GDRIVE }} github-target-filename: "${{ env.SYNERGY_PACKAGE_PREFIX }}-${{ matrix.target.name }}" - package-version: ${{ env.DESKFLOW_VERSION }} + gdrive-target-base-dir: ${{ vars.GDRIVE_TARGET_BASE_DIR }} + gdrive-secret-key: ${{ secrets.GOOGLE_DRIVE_KEY }} + gdrive-parent-folder-id: ${{ secrets.GOOGLE_DRIVE_TECH_DRIVE }} + package-version: ${{ env.SYNERGY_VERSION }} macos: name: ${{ matrix.target.name }} @@ -195,11 +202,15 @@ jobs: - name: Upload if: ${{ env.PACKAGE_UPLOAD == 'true' }} - uses: ./deskflow/.github/actions/dist-upload + uses: ./.github/actions/dist-upload with: - use-github: true + use-github: ${{ env.UPLOAD_TO_GITHUB }} + use-gdrive: ${{ env.UPLOAD_TO_GDRIVE }} github-target-filename: "${{ env.SYNERGY_PACKAGE_PREFIX }}-${{ matrix.target.name }}" - package-version: ${{ env.DESKFLOW_VERSION }} + gdrive-target-base-dir: ${{ vars.GDRIVE_TARGET_BASE_DIR }} + gdrive-secret-key: ${{ secrets.GOOGLE_DRIVE_KEY }} + gdrive-parent-folder-id: ${{ secrets.GOOGLE_DRIVE_TECH_DRIVE }} + package-version: ${{ env.SYNERGY_VERSION }} linux-matrix: runs-on: ubuntu-latest @@ -272,8 +283,12 @@ jobs: - name: Upload if: ${{ env.PACKAGE_UPLOAD == 'true' }} - uses: ./deskflow/.github/actions/dist-upload + uses: ./.github/actions/dist-upload with: - use-github: true + use-github: ${{ env.UPLOAD_TO_GITHUB }} + use-gdrive: ${{ env.UPLOAD_TO_GDRIVE }} github-target-filename: "${{ env.SYNERGY_PACKAGE_PREFIX }}-${{ matrix.distro.name }}" - package-version: ${{ env.DESKFLOW_VERSION }} + gdrive-target-base-dir: ${{ vars.GDRIVE_TARGET_BASE_DIR }} + gdrive-secret-key: ${{ secrets.GOOGLE_DRIVE_KEY }} + gdrive-parent-folder-id: ${{ secrets.GOOGLE_DRIVE_TECH_DRIVE }} + package-version: ${{ env.SYNERGY_VERSION }}