├── .github ├── ISSUE_TEMPLATE │ ├── bug.yaml │ ├── documentation.yaml │ └── feature.yaml └── workflows │ └── test.yaml ├── .gitignore ├── .prettierignore ├── .prettierrc.json ├── LICENSE ├── README.md ├── action.yml ├── assets └── banner.png ├── dist ├── index.js └── package.json ├── package-lock.json ├── package.json └── src ├── helpers ├── ExecOutput.js └── RunCommand.js ├── index.js ├── models └── Inputs.js └── steps ├── getInputs.js ├── install-appwrite.js ├── login-api.js ├── login-email.js ├── run-actions.js └── testing-appwrite.js /.github/ISSUE_TEMPLATE/bug.yaml: -------------------------------------------------------------------------------- 1 | name: "🐛 Bug Report" 2 | description: "Submit a bug report to help us improve" 3 | title: "🐛 Bug Report: " 4 | labels: [bug] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out our bug report form 🙏 10 | - type: textarea 11 | id: steps-to-reproduce 12 | validations: 13 | required: true 14 | attributes: 15 | label: "👟 Reproduction steps" 16 | description: "How do you trigger this bug? Please walk us through it step by step." 17 | placeholder: "When I ..." 18 | - type: textarea 19 | id: expected-behavior 20 | validations: 21 | required: true 22 | attributes: 23 | label: "👍 Expected behavior" 24 | description: "What did you think would happen?" 25 | placeholder: "It should ..." 26 | - type: textarea 27 | id: actual-behavior 28 | validations: 29 | required: true 30 | attributes: 31 | label: "👎 Actual Behavior" 32 | description: "What did actually happen? Add screenshots, if applicable." 33 | placeholder: "It actually ..." 34 | - type: dropdown 35 | id: github-actions-version 36 | attributes: 37 | label: "🎲 Github actions version" 38 | description: "What version of Appwrite are you running?" 39 | options: 40 | - Version 1.0 41 | - Different version (specify in environment) 42 | validations: 43 | required: true 44 | - type: dropdown 45 | id: operating-system 46 | attributes: 47 | label: "💻 Operating system" 48 | description: "What OS is your server / device running on?" 49 | options: 50 | - Linux 51 | - MacOS 52 | - Windows 53 | - Something else 54 | validations: 55 | required: true 56 | - type: textarea 57 | id: enviromnemt 58 | validations: 59 | required: false 60 | attributes: 61 | label: "🧱 Your Environment" 62 | description: "Is your environment customized in any way?" 63 | placeholder: "I use Cloudflare for ..." 64 | - type: checkboxes 65 | id: no-duplicate-issues 66 | attributes: 67 | label: "👀 Have you spent some time to check if this issue has been raised before?" 68 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 69 | options: 70 | - label: "I checked and didn't find similar issue" 71 | required: true 72 | - type: checkboxes 73 | id: read-code-of-conduct 74 | attributes: 75 | label: "🏢 Have you read the Code of Conduct?" 76 | options: 77 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 78 | required: true -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.yaml: -------------------------------------------------------------------------------- 1 | name: "📚 Documentation" 2 | description: "Report an issue related to documentation" 3 | title: "📚 Documentation: " 4 | labels: [documentation] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to make our documentation better 🙏 10 | - type: textarea 11 | id: issue-description 12 | validations: 13 | required: true 14 | attributes: 15 | label: "💭 Description" 16 | description: "A clear and concise description of what the issue is." 17 | placeholder: "Documentation should not ..." 18 | - type: checkboxes 19 | id: no-duplicate-issues 20 | attributes: 21 | label: "👀 Have you spent some time to check if this issue has been raised before?" 22 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 23 | options: 24 | - label: "I checked and didn't find similar issue" 25 | required: true 26 | - type: checkboxes 27 | id: read-code-of-conduct 28 | attributes: 29 | label: "🏢 Have you read the Code of Conduct?" 30 | options: 31 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 32 | required: true -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yaml: -------------------------------------------------------------------------------- 1 | name: 🚀 Feature 2 | description: "Submit a proposal for a new feature" 3 | title: "🚀 Feature: " 4 | labels: [feature] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out our feature request form 🙏 10 | - type: textarea 11 | id: feature-description 12 | validations: 13 | required: true 14 | attributes: 15 | label: "🔖 Feature description" 16 | description: "A clear and concise description of what the feature is." 17 | placeholder: "You should add ..." 18 | - type: textarea 19 | id: pitch 20 | validations: 21 | required: true 22 | attributes: 23 | label: "🎤 Pitch" 24 | description: "Please explain why this feature should be implemented and how it would be used. Add examples, if applicable." 25 | placeholder: "In my use-case, ..." 26 | - type: checkboxes 27 | id: no-duplicate-issues 28 | attributes: 29 | label: "👀 Have you spent some time to check if this issue has been raised before?" 30 | description: "Have you Googled for a similar issue or checked our older issues for a similar bug?" 31 | options: 32 | - label: "I checked and didn't find similar issue" 33 | required: true 34 | - type: checkboxes 35 | id: read-code-of-conduct 36 | attributes: 37 | label: "🏢 Have you read the Code of Conduct?" 38 | options: 39 | - label: "I have read the [Code of Conduct](https://github.com/appwrite/appwrite/blob/HEAD/CODE_OF_CONDUCT.md)" 40 | required: true -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | test: 8 | name: Test action 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout repository 12 | uses: actions/checkout@v4 13 | - uses: ./ 14 | with: 15 | method: email 16 | email: ${{ secrets.EMAIL }} 17 | password: ${{ secrets.PASSWORD }} 18 | actions: |- 19 | whoami 20 | - uses: ./ 21 | with: 22 | method: key 23 | key: ${{ secrets.API_KEY }} 24 | project: ${{ secrets.PROJECT_ID }} 25 | self_signed: true 26 | force: true 27 | all: true 28 | actions: |- 29 | pull functions --all --force 30 | push functions --all --force --async 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | *.local.test 4 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # artifacts 2 | dist/ 3 | # unsupported formats 4 | yarn.lock 5 | .gitignore 6 | .prettierignore 7 | .npmrc 8 | .nvmrc 9 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 300, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": true, 6 | "singleQuote": true, 7 | "trailingComma": "none", 8 | "bracketSpacing": true 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Appwrite 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Appwrite CLI for GitHub Actions 2 | 3 | ![banner.png](assets/banner.png) 4 | 5 | ![License](https://img.shields.io/github/license/appwrite/setup-for-appwrite.svg?v=1) 6 | ![Version](https://img.shields.io/badge/api%20version-1.5.6-blue.svg?v=1) 7 | 8 | Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. 9 | 10 | Use the CLI to integrate your CI with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. 11 | For full API documentation and tutorials, go to [https://appwrite.io/docs](https://appwrite.io/docs) 12 | 13 | ## Introduction 14 | 15 | This action can be used in many ways: 16 | 17 | - To add Appwrite CLI to your GitHub actions 18 | - To log in to your Appwrite instance using **email and password**. 19 | - To log in to your Appwrite instance using an **API key and project ID**. 20 | - Optionally: you can pass a list of action to execute using the Appwrite CLI. 21 | 22 | ### Inputes 23 | 24 | #### ``endpoint`` 25 | 26 | Required: **NO** 27 | 28 | Appwrite Endpoint, e.g. `https://cloud.appwrite.io/v1` 29 | 30 | #### ``method`` 31 | 32 | Required: **NO** 33 | 34 | Enter the login method to your Appwrite instance, available options 35 | 36 | - email 37 | - key 38 | 39 | When using email, you'll need to pass email and password 40 | 41 | ```yaml 42 | - name: Appwrite action 43 | uses: appwrite/setup-for-appwrite@v2 44 | with: 45 | method: email 46 | email: ${{ secrets.EMAIL }} 47 | password: ${{ secrets.PASSWORD }} 48 | ``` 49 | 50 | When using key you'll need to pass the API key and project ID 51 | 52 | ```yaml 53 | - name: Appwrite action 54 | uses: appwrite/setup-for-appwrite@v2 55 | with: 56 | method: key 57 | key: ${{ secrets.API_KEY }} 58 | project: ${{ vars.PROJECT_ID }} 59 | self_signed: true 60 | ``` 61 | 62 | #### ``email`` 63 | 64 | Required: **NO** 65 | 66 | User email 67 | 68 | #### ``password`` 69 | 70 | Required: **NO** 71 | 72 | User password 73 | 74 | #### ``project`` 75 | 76 | Required: **NO** 77 | 78 | Project ID 79 | 80 | #### ``key`` 81 | 82 | Required: **NO** 83 | 84 | API Key 85 | 86 | #### ``self_signed`` 87 | 88 | Required: **NO** 89 | 90 | Whether you are using a self-signed, local certificate 91 | 92 | #### ``force`` 93 | 94 | Required: **NO** 95 | 96 | When set to `true`, push or pull actions will have the `--force` flag 97 | 98 | #### ``all`` 99 | 100 | Required: **NO** 101 | 102 | When set to `true`, push or pull actions will have the `--all` flag 103 | 104 | #### ``actions`` 105 | 106 | Required: **NO** 107 | 108 | List of appwrite actions to execute, you can use write the command with or without the leading `appwrite` 109 | 110 | ```yaml 111 | actions: |- 112 | appwrite push functions 113 | push collections 114 | ``` 115 | 116 | ## Usage 117 | ### Basic example 118 | ```yaml 119 | name: List of users 120 | 121 | on: 122 | workflow_dispatch: 123 | 124 | jobs: 125 | migrate: 126 | runs-on: ubuntu-latest 127 | steps: 128 | - name: Checkout repository 129 | uses: actions/checkout@v4 130 | - name: Setup Appwrite 131 | uses: appwrite/setup-for-appwrite@v2 132 | - name: List users 133 | run: appwrite users list 134 | ``` 135 | 136 | ### Full email example 137 | ```yaml 138 | name: Database Migrations 139 | 140 | 141 | on: 142 | release: 143 | types: [ published ] 144 | 145 | jobs: 146 | migrate: 147 | runs-on: ubuntu-latest 148 | steps: 149 | - name: Checkout repository 150 | uses: actions/checkout@v4 151 | - name: Setup Appwrite 152 | uses: appwrite/setup-for-appwrite@v2 153 | with: 154 | method: email 155 | email: ${{ secrets.EMAIL }} 156 | password: ${{ secrets.PASSWORD }} 157 | force: true 158 | all: true 159 | actions: |- 160 | push collections 161 | 162 | ``` 163 | 164 | You can read more about the CLI [here](https://appwrite.io/docs/tooling/command-line/installation) and in our [docs](https://appwrite.io/docs). 165 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Setup Appwrite CLI' 2 | description: 'A GitHub Action to setup Appwrite CLI.' 3 | branding: 4 | icon: 'terminal' 5 | color: 'red' 6 | inputs: 7 | endpoint: 8 | description: 'Appwrite Endpoint' 9 | default: "https://cloud.appwrite.io/v1" 10 | required: false 11 | method: 12 | required: false 13 | description: "Login method either `key` or `email`" 14 | email: 15 | description: 'User email' 16 | required: false 17 | password: 18 | description: 'User password' 19 | required: false 20 | project: 21 | description: 'Project ID' 22 | required: false 23 | key: 24 | description: 'API Key' 25 | required: false 26 | self_signed: 27 | description: 'Whether you are using a self-signed, local certificate' 28 | required: false 29 | force: 30 | description: "When set to `true`, push or pull actions will have the `--force` flag" 31 | default: "false" 32 | required: false 33 | all: 34 | description: "When set to `true`, push or pull actions will have the `--all` flag" 35 | default: "false" 36 | required: false 37 | actions: 38 | required: false 39 | description: |- 40 | List of appwrite actions to execute, you can use write the command with or without the leading `appwrite` 41 | ```yaml 42 | actions: |- 43 | appwrite push functions 44 | push collections 45 | ``` 46 | runs: 47 | using: 'node20' 48 | main: 'dist/index.js' 49 | -------------------------------------------------------------------------------- /assets/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appwrite/setup-for-appwrite/955cc692f2556c84359f4f801f1ac4951bf4a62c/assets/banner.png -------------------------------------------------------------------------------- /dist/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module" 3 | } 4 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "setup-for-appwrite", 3 | "version": "2.0.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "setup-for-appwrite", 9 | "version": "2.0.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "@actions/core": "1.10.1", 13 | "@actions/exec": "1.1.1" 14 | }, 15 | "devDependencies": { 16 | "@vercel/ncc": "0.38.1", 17 | "prettier": "1.19.1" 18 | } 19 | }, 20 | "node_modules/@actions/core": { 21 | "version": "1.10.1", 22 | "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz", 23 | "integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==", 24 | "dependencies": { 25 | "@actions/http-client": "^2.0.1", 26 | "uuid": "^8.3.2" 27 | } 28 | }, 29 | "node_modules/@actions/exec": { 30 | "version": "1.1.1", 31 | "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", 32 | "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", 33 | "dependencies": { 34 | "@actions/io": "^1.0.1" 35 | } 36 | }, 37 | "node_modules/@actions/http-client": { 38 | "version": "2.2.1", 39 | "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.1.tgz", 40 | "integrity": "sha512-KhC/cZsq7f8I4LfZSJKgCvEwfkE8o1538VoBeoGzokVLLnbFDEAdFD3UhoMklxo2un9NJVBdANOresx7vTHlHw==", 41 | "dependencies": { 42 | "tunnel": "^0.0.6", 43 | "undici": "^5.25.4" 44 | } 45 | }, 46 | "node_modules/@actions/io": { 47 | "version": "1.1.3", 48 | "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", 49 | "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==" 50 | }, 51 | "node_modules/@fastify/busboy": { 52 | "version": "2.1.1", 53 | "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", 54 | "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", 55 | "engines": { 56 | "node": ">=14" 57 | } 58 | }, 59 | "node_modules/@vercel/ncc": { 60 | "version": "0.38.1", 61 | "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.1.tgz", 62 | "integrity": "sha512-IBBb+iI2NLu4VQn3Vwldyi2QwaXt5+hTyh58ggAMoCGE6DJmPvwL3KPBWcJl1m9LYPChBLE980Jw+CS4Wokqxw==", 63 | "dev": true, 64 | "bin": { 65 | "ncc": "dist/ncc/cli.js" 66 | } 67 | }, 68 | "node_modules/prettier": { 69 | "version": "1.19.1", 70 | "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", 71 | "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", 72 | "dev": true, 73 | "bin": { 74 | "prettier": "bin-prettier.js" 75 | }, 76 | "engines": { 77 | "node": ">=4" 78 | } 79 | }, 80 | "node_modules/tunnel": { 81 | "version": "0.0.6", 82 | "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", 83 | "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", 84 | "engines": { 85 | "node": ">=0.6.11 <=0.7.0 || >=0.7.3" 86 | } 87 | }, 88 | "node_modules/undici": { 89 | "version": "5.28.4", 90 | "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", 91 | "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", 92 | "dependencies": { 93 | "@fastify/busboy": "^2.0.0" 94 | }, 95 | "engines": { 96 | "node": ">=14.0" 97 | } 98 | }, 99 | "node_modules/uuid": { 100 | "version": "8.3.2", 101 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", 102 | "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", 103 | "bin": { 104 | "uuid": "dist/bin/uuid" 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "setup-for-appwrite", 3 | "version": "2.0.0", 4 | "license": "MIT", 5 | "description": "GitHub action for setup Appwrite CLI and login using API key or email and password", 6 | "main": "dist/index.js", 7 | "type": "module", 8 | "scripts": { 9 | "format": "prettier --write './**/*'", 10 | "format:check": "prettier --check './**/*'", 11 | "test": "echo \"Error: no test specified\" && exit 1", 12 | "unit": "echo \"Error: no unit test specified\" && exit 1", 13 | "build": "ncc build -o dist src/index.js", 14 | "semantic-release": "semantic-release" 15 | }, 16 | "dependencies": { 17 | "@actions/core": "1.10.1", 18 | "@actions/exec": "1.1.1" 19 | }, 20 | "devDependencies": { 21 | "@vercel/ncc": "0.38.1", 22 | "prettier": "1.19.1" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "https://github.com/appwrite/setup-for-appwrite.git" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/helpers/ExecOutput.js: -------------------------------------------------------------------------------- 1 | export default class ExecOutput { 2 | stdout = ''; 3 | exitCode = 0; 4 | } 5 | -------------------------------------------------------------------------------- /src/helpers/RunCommand.js: -------------------------------------------------------------------------------- 1 | import ExecOutput from './ExecOutput.js'; 2 | import * as exec from '@actions/exec'; 3 | 4 | export default class RunCommand { 5 | static async run(command, args = []) { 6 | const result = new ExecOutput(); 7 | const stdout = []; 8 | 9 | const listeners = { 10 | stdout: (data) => { 11 | stdout.push(data.toString()); 12 | }, 13 | stderr: (data) => { 14 | stdout.push(data.toString()); 15 | } 16 | }; 17 | 18 | result.exitCode = await exec.exec(command, args, { listeners, silent: true, ignoreReturnCode: true }); 19 | result.stdout = stdout.join(''); 20 | 21 | return result; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import { installAppwrite } from './steps/install-appwrite.js'; 3 | import { testingAppwrite } from './steps/testing-appwrite.js'; 4 | import { getInputs } from './steps/getInputs.js'; 5 | import { runActions } from './steps/run-actions.js'; 6 | import { loginEmail } from './steps/login-email.js'; 7 | import { loginApi } from './steps/login-api.js'; 8 | 9 | async function run() { 10 | if (await installAppwrite() !== 0) { 11 | core.setFailed(`Can't install Appwrite CLI`); 12 | return; 13 | } 14 | 15 | if (await testingAppwrite() !== 0) { 16 | core.setFailed(`Appwrite CLI is not available`); 17 | return; 18 | } 19 | 20 | const inputs = getInputs(); 21 | if (inputs === null || !inputs.method) { 22 | return; 23 | } 24 | 25 | if (inputs.method === 'key') { 26 | if (await loginApi(inputs.key, inputs.project, inputs.endpoint, inputs.selfSigned) !== 0) { 27 | core.setFailed(`Appwrite CLI was unable to log in using the provided credentials`); 28 | return; 29 | } 30 | } else { 31 | if (await loginEmail(inputs.email, inputs.password, inputs.endpoint) !== 0) { 32 | core.setFailed(`Appwrite CLI was unable to log in using the provided credentials`); 33 | return; 34 | 35 | } 36 | } 37 | 38 | if (inputs.actions.length !== 0) { 39 | const num = await runActions(inputs.actions); 40 | core.info(`Successfully executed ${num} actions`); 41 | } 42 | } 43 | 44 | await run(); 45 | -------------------------------------------------------------------------------- /src/models/Inputs.js: -------------------------------------------------------------------------------- 1 | export default class Inputs { 2 | endpoint = ''; 3 | method = ''; 4 | email = ''; 5 | password = ''; 6 | project = ''; 7 | key = ''; 8 | selfSigned =false; 9 | force = false; 10 | all = false; 11 | actions = []; 12 | } 13 | -------------------------------------------------------------------------------- /src/steps/getInputs.js: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import Inputs from '../models/Inputs.js'; 3 | 4 | 5 | export function getInputs() { 6 | core.info('Getting inputs'); 7 | const inputs = new Inputs(); 8 | 9 | inputs.endpoint = core.getInput('endpoint'); 10 | inputs.method = core.getInput('method'); 11 | 12 | if (inputs.method === 'key') { 13 | inputs.project = core.getInput('project'); 14 | inputs.key = core.getInput('key'); 15 | inputs.selfSigned = core.getInput('self_signed').toString() === 'true'; 16 | 17 | if (!inputs.key || !inputs.project) { 18 | core.error('project and key are require when using the key login method'); 19 | return null; 20 | } 21 | } else { 22 | inputs.email = core.getInput('email'); 23 | inputs.password = core.getInput('password'); 24 | 25 | if (!inputs.email || !inputs.password) { 26 | core.setFailed('email and password are require when using the email login method'); 27 | return null; 28 | } 29 | } 30 | 31 | inputs.force = core.getInput('force').toString() === 'true'; 32 | inputs.all = core.getInput('all').toString() === 'true'; 33 | 34 | const actions = core.getInput('actions'); 35 | 36 | if (actions.length > 0) { 37 | inputs.actions = actions.split(/\r\n|\r|\n/g).map((action) => { 38 | if (action.search(/appwrite/) === 0) { 39 | action = action.replace('appwrite', ''); 40 | } 41 | 42 | if (action.search(/pull|push/) === 0) { 43 | if (!action.includes('--all') && !action.includes('-a') && inputs.all) { 44 | action += ' --all'; 45 | } 46 | 47 | if (!action.includes('--force') && !action.includes('-f') && inputs.all) { 48 | action += ' --force'; 49 | } 50 | } 51 | 52 | 53 | return action; 54 | }); 55 | } 56 | 57 | return inputs; 58 | } 59 | -------------------------------------------------------------------------------- /src/steps/install-appwrite.js: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import RunCommand from '../helpers/RunCommand.js'; 3 | 4 | export async function installAppwrite() { 5 | core.info('Installing Appwrite'); 6 | const res = await RunCommand.run('npm', ['install', '-g', 'appwrite-cli']); 7 | 8 | return res.exitCode; 9 | } 10 | -------------------------------------------------------------------------------- /src/steps/login-api.js: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import RunCommand from '../helpers/RunCommand.js'; 3 | 4 | export async function loginApi(key, project, endpoint, selfSigned) { 5 | core.info('Login using API key and project ID'); 6 | const res = await RunCommand.run('appwrite', ['client', '--endpoint', endpoint, '--project-id', project, '--key', key, '--self-signed', selfSigned.toString()]); 7 | 8 | core.info(res.stdout); 9 | 10 | return res.exitCode; 11 | } 12 | -------------------------------------------------------------------------------- /src/steps/login-email.js: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import RunCommand from '../helpers/RunCommand.js'; 3 | 4 | export async function loginEmail(email, password, endpoint) { 5 | core.info('Login using email and password'); 6 | const res = await RunCommand.run('appwrite', ['login', '--email', email, '--password', password, '--endpoint', endpoint]); 7 | core.info(res.stdout); 8 | 9 | return res.exitCode; 10 | } 11 | -------------------------------------------------------------------------------- /src/steps/run-actions.js: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import RunCommand from '../helpers/RunCommand.js'; 3 | 4 | export async function runActions(actions) { 5 | let numberOfSuccessActions = 0; 6 | 7 | for (const action of actions) { 8 | const res = await RunCommand.run('appwrite', action.split(' ')); 9 | core.info(res.stdout); 10 | if (res.exitCode === 0) { 11 | numberOfSuccessActions++; 12 | } 13 | } 14 | 15 | return numberOfSuccessActions; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/steps/testing-appwrite.js: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import RunCommand from '../helpers/RunCommand.js'; 3 | 4 | 5 | export async function testingAppwrite() { 6 | core.info('Testing Appwrite'); 7 | const res = await RunCommand.run('appwrite', ['-v']); 8 | if(res.exitCode === 0) { 9 | core.info(`Using Appwrite version ${res.stdout}`); 10 | } 11 | 12 | return res.exitCode; 13 | } 14 | --------------------------------------------------------------------------------