Skip to content

Commit

Permalink
Add support for linking remote instances and projects initialization (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nsidnev authored Nov 30, 2021
1 parent ec28280 commit 84ac96b
Show file tree
Hide file tree
Showing 7 changed files with 655 additions and 32 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,72 @@ jobs:
- run: |
npm run all
test: # make sure the action works on a clean machine without building
name: Test CLI and server installation (CLI ${{ matrix.cli-version }} / server ${{ matrix.server-version }} / OS ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
cli-version: [stable, nightly]
server-version: [stable, nightly, 1.0-rc.2]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: ./
with:
cli-version: ${{ matrix.cli-version }}
server-version: ${{ matrix.server-version }}
- name: Verify installation
run: |
edgedb --version
edgedb-server --version
testproject:
name: Test integration with EdgeDB projects (CLI ${{ matrix.cli-version }} / server ${{ matrix.server-version }} / OS ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
cli-version: [stable, nightly]
server-version: [stable, nightly, 1.0-rc.2]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Create edgedb.toml
run: |
echo -e '[edgedb]\nserver-version = "1.0-rc.2"' >> edgedb.toml
- uses: ./
with:
cli-version: ${{ matrix.cli-version }}
server-version: ${{ matrix.server-version }}
- name: Verify installation
run: |
edgedb query "SELECT 'Hello from GitHub Actions'"
testprojectlink:
name: Test integration with EdgeDB projects using remote instances (CLI ${{ matrix.cli-version }})
runs-on: ubuntu-latest
strategy:
matrix:
cli-version: [stable, nightly]
fail-fast: false
services:
edgedb:
image: edgedb/edgedb:1-rc2
env:
EDGEDB_SERVER_SECURITY: insecure_dev_mode
ports:
- 5656:5656
steps:
- uses: actions/checkout@v2
- name: Create edgedb.toml
run: |
echo -e '[edgedb]\nserver-version = "1.0-rc.2"' >> edgedb.toml
- uses: ./
with:
server-dsn: edgedb://localhost:5656
cli-version: ${{ matrix.cli-version }}
server-version: none
- name: Verify installation
run: |
edgedb query "SELECT 'Hello from GitHub Actions'"
testwin:
runs-on: windows-latest
steps:
Expand Down
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
- 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-rc2
env:
EDGEDB_SERVER_SECURITY: insecure_dev_mode
ports:
- 5656:5656
steps:
- uses: actions/checkout@v2
- uses: edgedb/setup-edgedb@v1
with:
server-dsn: 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 = {
'server-dsn': 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
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ 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: ''
server-dsn:
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

0 comments on commit 84ac96b

Please sign in to comment.