diff --git a/README.md b/README.md index 8c00173..7a25bb6 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This action uploads the specified directory/files to Google Drive. ## Example +### Upload + ```yaml - name: Upload to Google Drive uses: satackey/action-google-drive@v1 @@ -17,6 +19,21 @@ This action uploads the specified directory/files to Google Drive. google-client-secret: ${{ secrets.GOOGLE_CLIENT_SECRET }} ``` +### Donwload + +```yaml +- name: Download from Google Drive + uses: satackey/action-google-drive@v1 + with: + skicka-tokencache-json: ${{ secrets.SKICKA_TOKENCACHE_JSON }} + download-from: /path/to/download + download-to: ./ + + # For those who set up Google Drive API client ID and secret themselves + google-client-id: ${{ secrets.GOOGLE_CLIENT_ID }} + google-client-secret: ${{ secrets.GOOGLE_CLIENT_SECRET }} +``` + ## Get ready This action uses [`skicka`](https://github.com/google/skicka) for uploading to Google Drive. @@ -70,9 +87,15 @@ Return to step 2 and proceed, and similarly **register your client ID and secret - `upload-from` optional Upload source path. Default is the current directory. -- `upload-to` optional +- `upload-to` **Required** for upload Upload destination path. +- `download-from` **Required** for download + Download source path. + +- `download-to` optional + Download destination path. Default is the current directory. + - `google-client-id` optional OAuth2.0 client ID of Google APIs when using skicka. **Required** for those who set up Google Drive API client ID and secret themselves. diff --git a/action.yml b/action.yml index 369165c..87904c3 100644 --- a/action.yml +++ b/action.yml @@ -1,8 +1,8 @@ -name: 'Upload to Google Drive' -description: 'Upload files to Google Drive' +name: Intaract with Google Drive +description: Upload/Download files to/from Google Drive branding: - icon: 'upload-cloud' + icon: upload-cloud color: 'gray-dark' inputs: @@ -17,7 +17,16 @@ inputs: upload-to: description: 'The path where the files to be uploaded is located' - required: true + required: false + + download-from: + description: The path where the files to download are located + required: false + + download-to: + description: The path where the files to be downloaded is located + required: false + default: ./ remove-outdated: description: 'Whether to delete files that do not exist locally' @@ -40,6 +49,8 @@ runs: SKICKA_TOKENCACHE_JSON: ${{ inputs.skicka-tokencache-json }} UPLOAD_FROM: ${{ inputs.upload-from }} UPLOAD_TO: ${{ inputs.upload-to }} + DOWNLOAD_FROM: ${{ inputs.download-from }} + DOWNLOAD_TO: ${{ inputs.download-to }} REMOVE_OUTDATED: ${{ inputs.remove-outdated }} GOOGLE_CLIENT_ID: ${{ inputs.google-client-id }} GOOGLE_CLIENT_SECRET: ${{ inputs.google-client-secret }} diff --git a/entrypoint.sh b/entrypoint.sh index 0cbbe08..6c9fe17 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,15 +13,27 @@ if [ -n "$GOOGLE_CLIENT_ID" ]; then sed -i -e "s/;clientsecret=YOUR_GOOGLE_APP_SECRET/clientsecret=$GOOGLE_CLIENT_SECRET/" ~/.skicka.config fi -skicka -no-browser-auth upload -ignore-times "$UPLOAD_FROM" "$UPLOAD_TO" +if [ -n "$DOWNLOAD_FROM" ]; then + echo 'Input download-from has been specified. This action will run the download.' + skicka -no-browser-auth download -ignore-times "$DOWNLOAD_FROM" "$DOWNLOAD_TO" +elif [ -n "$UPLOAD_TO" ]; then + echo 'Input upload-to has been specified. This action will run the upload.' + skicka -no-browser-auth upload -ignore-times "$UPLOAD_FROM" "$UPLOAD_TO" -# Remove outdated -if [ $REMOVE_OUTDATED == "true" ]; then - skicka -verbose download -ignore-times "$UPLOAD_TO" "$UPLOAD_FROM" 2>&1 | \ - sed "/Downloaded and wrote/!d" | \ - sed -E "s/.*bytes to //" | \ - xargs -I{} skicka rm "$UPLOAD_FROM{}" || true -elif [ $REMOVE_OUTDATED != "false" ]; then - echo '$REMOVE_OUTDATED must be "true" or "false".' + # Remove outdated + if [ $REMOVE_OUTDATED == "true" ]; then + # This command will download files that don't exist locally, + # and remove files from downloaded files list. + skicka -verbose download -ignore-times "$UPLOAD_TO" "$UPLOAD_FROM" 2>&1 | \ + sed "/Downloaded and wrote/!d" | \ + sed -E "s/.*bytes to //" | \ + xargs -I{} skicka rm "$UPLOAD_FROM{}" || true + elif [ $REMOVE_OUTDATED != "false" ]; then + echo '$REMOVE_OUTDATED must be "true" or "false".' + exit 1 + fi +else + echo 'Neither input download-from nor upload-to has been specified.' + echo 'You need to specify which one.' exit 1 fi