Skip to content

Commit

Permalink
Merge pull request #5 from satackey/enable-downloads
Browse files Browse the repository at this point in the history
Enable downloads
  • Loading branch information
satackey authored Jun 1, 2020
2 parents 765fc2d + 069767f commit f2dbc2f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 14 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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'
Expand All @@ -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 }}
30 changes: 21 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f2dbc2f

Please sign in to comment.