├── .env ├── .nvmrc ├── .gitignore ├── sample ├── demo.md └── sample2 │ └── demo2.md ├── .prettierrc.json ├── .github └── workflows │ └── main.yml ├── tsconfig.json ├── README.md ├── .vscode └── launch.json ├── action.yml ├── package.json ├── LICENSE ├── src └── main.ts └── dist └── main.js /.env: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v13.10.1 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | build -------------------------------------------------------------------------------- /sample/demo.md: -------------------------------------------------------------------------------- 1 | # Demo.md 2 | 3 | This is a demo file to be uploaded 4 | 5 | ## Heading 6 | 7 | ### Sub heading 8 | 9 | ## Heading 10 | -------------------------------------------------------------------------------- /sample/sample2/demo2.md: -------------------------------------------------------------------------------- 1 | # Demo.md 2 | 3 | This is a demo file to be uploaded 4 | 5 | ## Heading 6 | 7 | ### Sub heading 8 | 9 | ## Heading 10 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": false, 6 | "singleQuote": true, 7 | "trailingComma": "all", 8 | "bracketSpacing": false, 9 | "arrowParens": "always", 10 | "parser": "typescript" 11 | } 12 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: [push] 2 | 3 | jobs: 4 | local_development: 5 | runs-on: ubuntu-latest 6 | name: Testing action 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v2 10 | - name: Execute my action 11 | uses: ./ # Uses an action in the root directory 12 | with: 13 | DROPBOX_ACCESS_TOKEN: ${{ secrets.DROPBOX_ACCESS_TOKEN }} 14 | DROPBOX_DESTINATION_PATH_PREFIX: "/" 15 | GLOB: "sample/**/*.md" 16 | DEBUG: false 17 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": false, 15 | "noEmit": false, 16 | "jsx": "react", 17 | "outDir": "dist" 18 | }, 19 | "include": ["src/**/*"] 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deploy-to-dropbox 2 | 3 | A GitHub Action to deploy to Dropbox 4 | 5 | ## Initialisation 6 | 7 | Follow [this guide](https://preventdirectaccess.com/docs/create-app-key-access-token-for-dropbox-account/#access-token) to create and get your access token 8 | 9 | Save the token to your repository `Settings > Secrets`: 10 | 11 | - Name: `DROPBOX_ACCESS_TOKEN` 12 | - Value: `YOUR_TOKEN_FROM_DROPBOX_APP_CONSOLE` 13 | 14 | 15 | ## Developing 16 | 17 | For the lazy ... 18 | ```bash 19 | git add -A && git commit -m "ci" && git tag -a -m "ci" v1.0.5 && git push --follow-tags 20 | ``` -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "pwa-node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "skipFiles": ["/**"], 12 | "program": "${workspaceFolder}/dist/index.js", 13 | "preLaunchTask": "tsc: build - tsconfig.json", 14 | "outFiles": ["${workspaceFolder}/dist/**/*.js"], 15 | "envFile": "${workspaceFolder}/.env" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Deploy to Dropbox' 2 | description: 'This action will handle the deployment process of your project to Dropbox.' 3 | author: 'aTable' 4 | branding: 5 | icon: 'upload-cloud' 6 | color: 'black' 7 | runs: 8 | using: 'node12' 9 | main: 'dist/index.js' 10 | inputs: 11 | DROPBOX_ACCESS_TOKEN: 12 | description: 'Value should be a secret that is set in your repository settings' 13 | required: true 14 | 15 | GLOB: 16 | description: 'Glob that you want to save to Dropbox e.g dir1/dir2/**/*.md or **/*.txt' 17 | required: true 18 | 19 | DROPBOX_DESTINATION_PATH_PREFIX: 20 | description: 'The destination path prefix to save to in Dropbox. This will prepend the individual globs. Default value is "/"' 21 | required: false 22 | default: "/" 23 | 24 | DEBUG: 25 | description: "Enable debugging." 26 | required: false 27 | 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deploy-to-dropbox", 3 | "version": "1.0.0", 4 | "description": "A GitHub Action to deploy to Dropbox", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "build": "tsc && ncc build dist/main.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/aTable/deploy-to-dropbox.git" 13 | }, 14 | "author": "", 15 | "license": "MIT", 16 | "bugs": { 17 | "url": "https://github.com/aTable/deploy-to-dropbox/issues" 18 | }, 19 | "homepage": "https://github.com/aTable/deploy-to-dropbox#readme", 20 | "dependencies": { 21 | "@actions/core": "^1.9.1", 22 | "@actions/github": "^2.1.1", 23 | "@types/node": "^13.9.3", 24 | "dropbox": "^4.0.30", 25 | "glob": "^7.1.6" 26 | }, 27 | "devDependencies": { 28 | "@zeit/ncc": "^0.22.0", 29 | "node-fetch": "^2.6.7", 30 | "typescript": "^3.8.3" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 aTable 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | const Dropbox = require('dropbox').Dropbox 2 | const fs = require('fs') 3 | const fetch2 = require('node-fetch') 4 | const core = require('@actions/core') 5 | const github = require('@actions/github') 6 | const glob = require('glob') 7 | 8 | const accessToken = core.getInput('DROPBOX_ACCESS_TOKEN') 9 | const globSource = core.getInput('GLOB') 10 | const dropboxPathPrefix = core.getInput('DROPBOX_DESTINATION_PATH_PREFIX') 11 | const isDebug = core.getInput('DEBUG') 12 | const dropbox = new Dropbox({accessToken, fetch: fetch2}) 13 | 14 | function uploadMuhFile(filePath: string): Promise { 15 | const file = fs.readFileSync(filePath) 16 | const destinationPath = `${dropboxPathPrefix}${filePath}` 17 | if (isDebug) console.log('uploaded file to Dropbox at: ', destinationPath) 18 | return dropbox 19 | .filesUpload({path: destinationPath, contents: file}) 20 | .then((response: any) => { 21 | if (isDebug) console.log(response) 22 | return response 23 | }) 24 | .catch((error: any) => { 25 | if (isDebug) console.error(error) 26 | return error 27 | }) 28 | } 29 | 30 | glob(globSource, {}, (err: any, files: string[]) => { 31 | if (err) core.setFailed('Error: glob failed', err) 32 | Promise.all(files.map(uploadMuhFile)) 33 | .then((all) => { 34 | console.log('all files uploaded', all) 35 | }) 36 | .catch((err) => { 37 | console.error('error', err) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /dist/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var Dropbox = require('dropbox').Dropbox; 3 | var fs = require('fs'); 4 | var fetch2 = require('node-fetch'); 5 | var core = require('@actions/core'); 6 | var github = require('@actions/github'); 7 | var glob = require('glob'); 8 | var accessToken = core.getInput('DROPBOX_ACCESS_TOKEN'); 9 | var globSource = core.getInput('GLOB'); 10 | var dropboxPathPrefix = core.getInput('DROPBOX_DESTINATION_PATH_PREFIX'); 11 | var isDebug = core.getInput('DEBUG'); 12 | var dropbox = new Dropbox({ accessToken: accessToken, fetch: fetch2 }); 13 | function uploadMuhFile(filePath) { 14 | var file = fs.readFileSync(filePath); 15 | var destinationPath = "" + dropboxPathPrefix + filePath; 16 | if (isDebug) 17 | console.log('uploaded file to Dropbox at: ', destinationPath); 18 | return dropbox 19 | .filesUpload({ path: destinationPath, contents: file }) 20 | .then(function (response) { 21 | if (isDebug) 22 | console.log(response); 23 | return response; 24 | }) 25 | .catch(function (error) { 26 | if (isDebug) 27 | console.error(error); 28 | return error; 29 | }); 30 | } 31 | glob(globSource, {}, function (err, files) { 32 | if (err) 33 | core.setFailed('Error: glob failed', err); 34 | Promise.all(files.map(uploadMuhFile)) 35 | .then(function (all) { 36 | console.log('all files uploaded', all); 37 | }) 38 | .catch(function (err) { 39 | console.error('error', err); 40 | }); 41 | }); 42 | --------------------------------------------------------------------------------