Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for linking remote instances and projects initialization #22

Merged
merged 11 commits into from
Nov 30, 2021
102 changes: 101 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,104 @@ both available in `PATH`.

# Usage

See [action.yml](action.yml)
See [action.yml](action.yml) for the action's specification.

How this action works:

This action executes different commands depending on state of files in repository and inputs for action in workflow. It can:
1. Install EdgeDB tools (CLI and server)
2. Create new EdgeDB instance
3. Initialize new [EdgeDB project](https://www.edgedb.com/docs/cli/edgedb_project/index) or link an existing one to remote instance

The following examples show how to use this action.

Example (installs stable EdgeDB CLI with server and makes them available in `$PATH`)
Note: if your repository has `edgedb.toml` file, then this action will also initialize new project for your workflow.
Otherwise, it will just install EdgeDB CLI and executable server that you can use on your own.

```yaml
on: push

jobs:
test:
runs-on: ubuntu-latest
name: CI with EdgeDB action
steps:
- uses: actions/checkout@v2
- uses: edgedb/setup-edgedb@v1
- run: edgedb --version
```

Example (installs latest EdgeDB CLI without server and makes CLI available in `$PATH`)
```yaml
on: push

jobs:
test:
runs-on: ubuntu-latest
name: CI with EdgeDB action
steps:
- uses: actions/checkout@v2
- uses: edgedb/setup-edgedb@v1
with:
cli-version: nightly
server-version: none
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this will no longer work as none equals to non-specifying the version at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you omit server-version in the workflow file, actions will use "stable" as default value as it was before. I haven't changed this behavior from previous version. As a result, first example installs both CLI and server, while this one only installs the CLI. I think that's the equivalent of the cli-only option you mentioned about above, no?

- run: edgedb --version
```

Example (installs EdgeDB CLI with server, creates new EdgeDB instance and links it using `edgedb project init`)
NOTE: this assumes that repository for the project has already been initialized
using `edgedb project init` and `edgedb.toml` file exists in the repository.
```yaml
on: push

jobs:
test:
runs-on: ubuntu-latest
name: CI with EdgeDB action
steps:
- uses: actions/checkout@v2
- uses: edgedb/setup-edgedb@v1
- run: edgedb query "SELECT 'Hello from GitHub Actions!'"
```

Example (same as one above, but using `services` from GitHub Actions and `edgedb project init --link`)
```yaml
on: push

jobs:
test:
runs-on: ubuntu-latest
name: CI with EdgeDB action
services:
edgedb:
image: edgedb/edgedb:1-rc1
env:
EDGEDB_SERVER_INSECURE_DEV_MODE: 1
ports:
- 5656:5656
steps:
- uses: actions/checkout@v2
- uses: edgedb/setup-edgedb@v1
with:
project-link: edgedb://localhost:5656
instance-name: ci_edgedb_instance # optional
- run: edgedb query "SELECT 'Hello from GitHub Actions!'"
```

Example (creates new instance, but overrides `server-version` from `edgedb.toml` if project initialization is to be used)
```yaml
on: push

jobs:
test:
runs-on: ubuntu-latest
name: CI with EdgeDB action
steps:
- uses: actions/checkout@v2
- uses: edgedb/setup-edgedb@v1
with:
server-version: 1.0-rc.2
instance-name: ci_edgedb_instance
- run: edgedb query "SELECT 'Hello from GitHub Actions!'"
```
44 changes: 42 additions & 2 deletions __tests__/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ process.env['RUNNER_TEMP'] = tempDir
describe('setup-edgedb', () => {
let inputs = {} as any
let inSpy: jest.SpyInstance
let inBooleanSpy: jest.SpyInstance
let cnSpy: jest.SpyInstance
let logSpy: jest.SpyInstance
let dbgSpy: jest.SpyInstance
Expand All @@ -41,9 +42,13 @@ describe('setup-edgedb', () => {
// @actions/core
console.log('::stop-commands::stoptoken')
process.env['GITHUB_PATH'] = ''
inputs = {}
inputs = {
'project-link': false
}
inSpy = jest.spyOn(core, 'getInput')
inSpy.mockImplementation(name => inputs[name])
inSpy.mockImplementation(name => inputs[name] || '')
inBooleanSpy = jest.spyOn(core, 'getBooleanInput')
inBooleanSpy.mockImplementation(name => inputs[name])

// @actions/tool-cache
dlSpy = jest.spyOn(tc, 'downloadTool')
Expand Down Expand Up @@ -96,6 +101,41 @@ describe('setup-edgedb', () => {

findSpy.mockImplementation(() => '')

const cliPath = path.normalize('/cache/edgedb/1.0.0-alpha.7')
cacheSpy.mockImplementation(async () => cliPath)

await main.run()

fs.unlinkSync(tmp)
fs.rmdirSync(tmpdir)

expect(dlSpy).toHaveBeenCalled()
expect(logSpy).toHaveBeenCalledWith(
`Downloading edgedb-cli ${resolvedVersion} - ${os.arch} from ${expectedUrl}`
)
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${cliPath}${os.EOL}`)
})

it('Installs server', async () => {
let versionSpec = '1.0.0-alpha.7'
let resolvedVersion = versionSpec

inputs['cli-version'] = '>=1.0.0-alpha.5 <=1.0.0-alpha.7'
inputs['server-version'] = 'stable'

const baseDist = main.getBaseDist(os.arch(), os.platform())
const pkgBase = `https://packages.edgedb.com/archive/${baseDist}`
const expectedUrl = pkgBase + '/edgedb-cli_1.0.0-alpha.7_2020121617'

const tmpdir = fs.mkdtempSync('edgedb-setup')
let tmp = path.join(tmpdir, 'foo')
fs.closeSync(fs.openSync(tmp, 'w'))
tmp = fs.realpathSync(tmp)

dlSpy.mockImplementation(async () => tmp)

findSpy.mockImplementation(() => '')

execSpy.mockImplementation(async (cmd, args, opts: ExecOptions) => {
if (args[0] === 'server' && args[1] === 'install') {
return 0
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ inputs:
stable release, or "nightly" for the latest nightly build,
or "none" to skip installaion. Defaults to "stable".
default: 'stable'
instance-name:
required: false
description: >
Name of EdgeDB instance to be used when creating new instance,
linking or initializing the project. If not set, the name will be auto-generated.
default: ''
project-link:
required: false
description: >
If set, specifies the DSN of a remote EdgeDB instance to link to instead of initializing a new local instance.
By default, a new instance will be initialized.
default: 'false'
runs:
using: 'node12'
main: 'dist/index.js'
Loading