Skip to content

Commit

Permalink
feat(delete): add delete action (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbioteau authored Jun 24, 2024
1 parent 2222394 commit 9cba154
Show file tree
Hide file tree
Showing 14 changed files with 56,122 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ jobs:
exit 1
fi
if [ "$(git diff --ignore-space-at-eol --text delete/dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff --ignore-space-at-eol --text delete/dist/
exit 1
fi
# If `dist/` was different than expected, and this was not a Dependabot
# PR, upload the expected version as a workflow artifact.
- if: ${{ failure() && steps.diff.outcome == 'failure' }}
Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
mkdir -p output/files
echo 'Hello World' > output/files/hello.txt
- name: Test Local Action
- name: Test Local Upload Action
id: test-action
uses: ./upload
with:
Expand All @@ -119,3 +119,30 @@ jobs:
- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.file-id }}"

test-delete-action:
needs: test-upload-action
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Retrieve secrets from Keeper
uses: Keeper-Security/ksm-action@v1
with:
keeper-secret-config: ${{ secrets.KSM_CONFIG }}
secrets: |
${{ vars.KEEPER_GOOGLE_SERVICE_ACCOUNT_RECORD_ID }}/field/password > env:GDRIVE_SERVICE_ACCOUNT_CREDENTIALS
- name: Test Local Delete Action
id: test-action
uses: ./delete
with:
credentials: ${{ env.GDRIVE_SERVICE_ACCOUNT_CREDENTIALS }}
parent-folder-id: ${{ vars.GDRIVE_GITHUB_ACTION_FOLDER }}
target-filepath: output/community/

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.file-id }}"
16 changes: 16 additions & 0 deletions __tests__/delete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Unit tests for the action's entrypoint, src/index.ts
*/
import * as main from '../src/main'

// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'runDelete').mockImplementation()

describe('delete', () => {
it('calls runDelete when imported', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/delete')

expect(runMock).toHaveBeenCalled()
})
})
38 changes: 38 additions & 0 deletions delete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Google Drive Delete Action

## Usage

### Inputs

| Name | Description | Required |
| - | - | - |
| `credentials` | Google API credentials in base64 format. | `true` |
| `parent-folder-id` | The parent folder ID in Google Drive. | `true` |
| `target-filepath` | The remote file path in Google Drive of the uploaded file relative to the given parent folder. Use parent folder root with source filename when not set. | `true` |

### Outputs

| Name | Description |
| - | - |
| `file-id` | The ID of the uploaded file. |

## Examples

```yaml
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Delete file from Google Drive
id: gdrive-delete
uses: bonitasoft/gdrive-action/delete@v1
with:
credentials: ${{ secrets.GDRIVE_CREDENTIALS }} # credentials stored as a GitHub secret
parent-folder-id: ${{ vars.GDRIVE_FOLDER_ID }} # folder id stored as a GitHub variable
target-filepath: test/hello_1.txt

- name: Print Output
id: output
run: echo "${{ steps.gdrive-upload.outputs.file-id }}"
```
24 changes: 24 additions & 0 deletions delete/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'gdrive-delete-action'
description: 'GitHub Action that delete files from Google Drive.'
author: 'Bonitasoft'

inputs:
credentials:
description: 'Google API credentials in base64 format.'
required: true
parent-folder-id:
description: 'The parent folder ID in Google Drive.'
required: true
target-filepath:
required: true
description:
'The remote file path in Google Drive of the file to delete relative to the
given parent folder.'

outputs:
file-id:
description: 'The ID of the deleted file.'

runs:
using: node20
main: dist/index.js
Loading

0 comments on commit 9cba154

Please sign in to comment.