Download Google Drive File #128
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Download Google Drive File' | |
| env: | |
| ARTIFACT_NAME: GoogleDriveFile | |
| on: | |
| # TODO: swap the workflow dispatch to trigger on the deployment flow and make the download workflow the called resuable workflow | |
| workflow_dispatch: | |
| inputs: | |
| tags: | |
| description: "Google AppScript Trigger for Deployment" | |
| required: false | |
| type: string | |
| jobs: | |
| download: | |
| name: Install Python and Download File from Google Drive | |
| runs-on: ubuntu-latest | |
| env: | |
| GOOGLE_FILE_ID: ${{ secrets.GOOGLE_FILE_ID }} | |
| GOOGLE_SERVICE_ACCOUNT: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }} | |
| WORKING_DIR: ./.github/scripts | |
| REUSABLE_WORKFLOW_PATH: teracross/webhosting/.github/workflows/deploy.yaml@main | |
| defaults: | |
| run: | |
| shell: bash | |
| working-directory: ${{env.WORKING_DIR}} | |
| outputs: | |
| file: ${{steps.verification.outputs.nonEmpty}} | |
| steps: | |
| - name: Checkout Github repository | |
| uses: actions/checkout@v4 | |
| - name: setup Python 3.10+ on runner | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| cache: 'pip' # caching pip dependencies | |
| - name: Install Python Dependencies | |
| run: pip install -r requirements.txt | |
| - name: Create credentials file for Google | |
| run: | | |
| echo $GOOGLE_SERVICE_ACCOUNT > services_encoded.json | |
| echo "::debug:: $(wc -c services_encoded.json)" | |
| cat services_encoded.json | base64 -di > services.json | |
| echo "::debug:: $(wc -c services.json)" | |
| - name: Download file from Google Drive | |
| run: python3 ./GoogleDriveFileDownloader.py | |
| - id: verification | |
| name: Verify non-empty file was downloaded | |
| run: | | |
| if [ -s index.html ]; then | |
| echo "nonEmpty=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "nonEmpty=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Validate job outputs stored properly | |
| run: echo "Job output is ${{ toJson(steps.verification.outputs.nonEmpty) }}" | |
| - name: Cache the file - to be used in deployment workflow | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{env.ARTIFACT_NAME}} | |
| path: ${{env.WORKING_DIR}}/index.html | |
| retention-days: 7 | |
| overwrite: true | |
| include-hidden-files: true | |
| if: ${{ steps.verification.outputs.nonEmpty }} | |
| - name: cleanup - ensure credentials and temporary files removed from runner | |
| run: | | |
| rm -f services.json | |
| rm -f services_decoded.json | |
| rm -f index.html | |
| if: ${{ always() }} | |
| trigger-deployment: | |
| uses: teracross/webhosting/.github/workflows/deploy.yaml@main | |
| needs: download | |
| with: | |
| artifact-name: ${{github.env.ARTIFACT_NAME}} | |
| permissions: | |
| id-token: write | |
| contents: read | |
| if: ${{ needs.download.outputs.file }} | |
| secrets: inherit | |