Skip to content

Commit 08aea50

Browse files
chore(ci): use with-connect in integration tests (#45)
1 parent b600fdd commit 08aea50

File tree

7 files changed

+72
-87
lines changed

7 files changed

+72
-87
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,51 @@ on:
55
tags: [v*]
66
pull_request:
77
branches: [main]
8-
env:
9-
RSC_LICENSE: ${{ secrets.RSC_LICENSE }}
108
jobs:
11-
main:
9+
test:
1210
strategy:
1311
matrix:
1412
os:
1513
- ubuntu-latest
1614
node:
1715
- 18.x
1816
- 20.x
17+
connect-version:
18+
- preview
19+
# This version is the first Docker image that has R 4.3, which the
20+
# example app requires.
21+
- "2024.05.0"
1922
runs-on: ${{ matrix.os }}
2023
steps:
21-
- uses: actions/checkout@v4
22-
- uses: actions/setup-node@v4
24+
- uses: actions/checkout@v6
25+
- uses: actions/setup-node@v6
2326
with:
2427
node-version: ${{ matrix.node }}
2528
- run: npm install
26-
- run: make
29+
- run: npm run lint
30+
- run: npm run build
31+
- uses: posit-dev/with-connect@main
32+
with:
33+
license: ${{ secrets.CONNECT_LICENSE_FILE }}
34+
version: ${{ matrix.connect-version }}
35+
command: npm test
2736
- run: git diff --exit-code
28-
- if: failure()
29-
run: docker compose logs
30-
- run: make down
37+
38+
publish:
39+
needs: test
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v6
43+
- uses: actions/setup-node@v6
44+
with:
45+
node-version: 20.x
46+
- run: npm install
47+
- run: npm run build
3148
- run: printf '//registry.npmjs.org/:_authToken=%s\n' "${NPM_AUTH_TOKEN}" | tee .npmrc
3249
env:
3350
NPM_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
3451
- run: npm info
35-
- if: matrix.node == '20.x' && startsWith(github.ref, 'refs/tags')
52+
- if: startsWith(github.ref, 'refs/tags')
3653
run: npm publish
3754
- if: startsWith(github.ref, 'refs/heads')
3855
run: npm publish --dry-run

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ npm-debug.log*
4343
pids
4444
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4545
typings/
46+
47+
# License files
48+
*.lic

Makefile

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
RSC_LICENSE ?=
1+
CONNECT_LICENSE_FILE ?= rstudio-connect.lic
22
SHELL := bash
33
VERSION := $(shell node -e 'console.log(require("$(CURDIR)/package.json").version)')
44

55
npm-%:
66
npm run $*
77

88
.PHONY: all
9-
all: up npm-lint lib/main.js npm-test
9+
all: npm-lint lib/main.js test
10+
11+
.PHONY: test
12+
test:
13+
uvx with-connect --license "$(CONNECT_LICENSE_FILE)" -- npm test
1014

1115
.PHONY: publish
1216
publish: lib/main.js
@@ -26,19 +30,3 @@ clean:
2630
.PHONY: distclean
2731
distclean: clean
2832
rm -rf .cache/
29-
30-
.PHONY: up
31-
up: .require-license
32-
docker compose port connect 3939 2>/dev/null | if ! grep -q ':23939$$'; then \
33-
docker compose up -d --wait; \
34-
fi
35-
36-
.PHONY: down
37-
down:
38-
docker compose down --remove-orphans
39-
40-
.PHONY: .require-license
41-
.require-license:
42-
ifndef RSC_LICENSE
43-
$(error Missing required RSC_LICENSE env var)
44-
endif

__tests__/main.spec.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as rsconnect from '../src/main'
88
jest.setTimeout(1000 * 60 * 2)
99

1010
const SEED_ADMIN_CONFIG: rsconnect.APIClientConfiguration = {
11-
apiKey: '21232f297a57a5a743894a0e4a801fc3',
12-
baseURL: 'http://127.0.0.1:23939/__api__'
11+
apiKey: process.env.CONNECT_API_KEY as string,
12+
baseURL: `${process.env.CONNECT_SERVER as string}/__api__`
1313
}
1414

1515
describe('rsconnect', () => {
@@ -109,4 +109,37 @@ describe('rsconnect', () => {
109109
})
110110
})
111111
})
112+
113+
describe('EnvironmentUpdater', () => {
114+
it('updateAppEnvironment', async () => {
115+
// Deploy an app to get a valid appGUID
116+
const top = execSync('git rev-parse --show-toplevel').toString().trim()
117+
const plumberManifest = path.join(top, '__tests__/apps/plumber/manifest.json')
118+
const client = new rsconnect.APIClient(SEED_ADMIN_CONFIG)
119+
const deployer = new rsconnect.Deployer(client)
120+
121+
const deployResp = await deployer.deployManifest({
122+
manifestPath: plumberManifest,
123+
appIdentifier: '/env-updater-test'
124+
})
125+
expect(deployResp.appGuid).not.toBeNull()
126+
127+
// Wait for deployment to complete
128+
const poller = new rsconnect.ClientTaskPoller(client, deployResp.taskId)
129+
for await (const result of poller.poll()) {
130+
expect(result).not.toBeNull()
131+
}
132+
133+
// Set environment variables using EnvironmentUpdater
134+
process.env.CONNECT_ENV_SET_TEST_VAR = 'test-value'
135+
const envUpdater = new rsconnect.EnvironmentUpdater(client)
136+
const envVars = await envUpdater.updateAppEnvironment(deployResp.appGuid)
137+
138+
// Verify the environment variable was set
139+
expect(envVars).toContain('TEST_VAR')
140+
141+
// Clean up
142+
delete process.env.CONNECT_ENV_SET_TEST_VAR
143+
})
144+
})
112145
})

__tests__/rstudio-connect.test.gcfg

Lines changed: 0 additions & 42 deletions
This file was deleted.

docker-compose.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"access": "public"
2222
},
2323
"scripts": {
24+
"prebuild": "node -e \"const p=require('./package.json'); const fs=require('fs'); fs.writeFileSync('src/Version.ts', '// WARNING: this file is generated\\nexport const Version = \\\"' + p.version + '\\\"\\n')\"",
2425
"build": "tsc",
2526
"lint": "ts-standard --fix ./src/*.ts ./__tests__/*.ts",
2627
"test": "jest"

0 commit comments

Comments
 (0)