Skip to content

Commit

Permalink
CI script reorganization
Browse files Browse the repository at this point in the history
- Updating ci script to use latest shutdown logic
- Removed unneeded tests
- Split browser tests into ones that need a gl instance those that down
- Removing the need to run the full e2e test unless its a release branch
- Moved the most tested release tests (the exports) into a integration test since it doesnt require a full gitlab instance for testing
  • Loading branch information
jdalrymple committed Jan 24, 2024
1 parent e76b91b commit ac69507
Show file tree
Hide file tree
Showing 15 changed files with 292 additions and 94 deletions.
65 changes: 37 additions & 28 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ format:
- main
- next
needs:
- install
- test:live:setup
- build

.test:e2e:base:
extends: .test:integration:base
Expand Down Expand Up @@ -264,9 +263,9 @@ test:live:setup:
when: always
- if: $CI_COMMIT_BRANCH == "next" || $CI_COMMIT_BRANCH =~ /^pr-[0-9]+$/
when: manual
allow_failure: true
needs:
- build
allow_failure: false
variables:
GITLAB_PERSONAL_ACCESS_TOKEN: gitbeaker
CONTAINER_NAME: gitlab-${CI_PIPELINE_ID}
Expand All @@ -287,8 +286,8 @@ test:live:setup:
--container-arg="-c" \
--container-arg="printf '#!/usr/bin/env ruby \nu = User.first \nu.admin = true \nu.save! \nt = PersonalAccessToken.new({ user: u, name: \"gitbeaker\", scopes: [\"api\", \"read_user\"]}) \nt.expires_at = 365.days.from_now \nt.set_token(ENV[\"PERSONAL_ACCESS_TOKEN\"]) \nt.save! \nputs t.token\n' > /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/40_access_token.rb && /assets/wrapper" \
--container-env ^~^GITLAB_ROOT_PASSWORD=${GITLAB_ROOT_PASSWORD}~PERSONAL_ACCESS_TOKEN=${GITLAB_PERSONAL_ACCESS_TOKEN}~GITLAB_OMNIBUS_CONFIG="gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0', '172.17.0.1'];" \
--metadata SELF_DESTRUCT_INTERVAL_MINUTES=15 \
--metadata-from-file startup-script=./scripts/shutdown.sh \
--max-run-duration=25m
--instance-termination-action=DELETE
--format='get(networkInterfaces[0].accessConfigs[0].natIP)'\
| head -2 | tail -1 )
Expand All @@ -309,10 +308,10 @@ test:live:teardown:
stage: test
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
needs:
- test:integration:rest
- test:e2e:core
- test:e2e:cli
- test:e2e:rest
- test:e2e:rest:browser
- test:e2e:rest:nodejs
when: always
only:
refs:
Expand All @@ -327,22 +326,30 @@ test:live:teardown:
- gcloud compute instances delete gitlab-${CI_PIPELINE_ID} --zone=northamerica-northeast1-b

## Integration Tests
test:integration:rest:
extends: .test:integration:base
script: yarn test:integration --projects=@gitbeaker/rest
test:integration:rest:browser:
extends: .test:e2e:base
image: mcr.microsoft.com/playwright:v1.40.0-focal
before_script:
# reinstall swc due to missing binding for ubuntu image
- yarn add @swc/core
script: yarn test:integration:browser --projects=@gitbeaker/rest

## End-to-End Tests
test:e2e:core:
extends: .test:e2e:base
script: yarn test:e2e --projects=@gitbeaker/core

test:e2e:rest:
test:e2e:rest:browser:
extends: .test:e2e:base
image: mcr.microsoft.com/playwright:v1.40.0-focal
before_script:
# reinstall swc due to missing binding for ubuntu image
- yarn add @swc/core
script: yarn test:e2e --projects=@gitbeaker/rest
script: yarn test:e2e:browser --projects=@gitbeaker/rest

test:e2e:rest:nodejs:
extends: .test:e2e:base
script: yarn test:e2e:nodejs --projects=@gitbeaker/rest

test:e2e:cli:
extends: .test:e2e:base
Expand Down Expand Up @@ -374,41 +381,43 @@ release:special:
extends: .release:base
needs:
- build
- test:integration:rest
- test:e2e:core
- test:e2e:cli
- test:e2e:rest
- test:e2e:rest:browser
- test:e2e:rest:nodejs
only:
refs:
- /^pr-[0-9]+$/

script:
- echo "Checking for special release..."
- |
if [[ $CI_COMMIT_BRANCH =~ ^pr-[0-9]*$ ]]; then
pr_id="${CI_COMMIT_BRANCH//[!0-9]/}"
- echo 'release'
# - echo "Checking for special release..."
# - |
# if [[ $CI_COMMIT_BRANCH =~ ^pr-[0-9]*$ ]]; then
# pr_id="${CI_COMMIT_BRANCH//[!0-9]/}"

export CI_MERGE_REQUEST_ID=$pr_id
export CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$CI_COMMIT_BRANCH
# export CI_MERGE_REQUEST_ID=$pr_id
# export CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$CI_COMMIT_BRANCH

labels=$(yarn auto label --pr $pr_id)
# labels=$(yarn auto label --pr $pr_id)

if [[ "$labels" =~ "release:canary" ]]; then
yarn release:canary
fi
fi
# if [[ "$labels" =~ "release:canary" ]]; then
# yarn release:canary
# fi
# fi

## Production
release:
extends: .release:base
needs:
- build
- test:integration:rest
- test:e2e:core
- test:e2e:cli
- test:e2e:rest
- test:e2e:rest:browser
- test:e2e:rest:nodejs
- test:unit:teardown
only:
refs:
- main
- next
script: yarn release
script: echo 'release' #yarn release
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.turbo
reports
coverage
dist
package.json
Expand Down
9 changes: 7 additions & 2 deletions packages/requester-utils/test/unit/BaseResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ describe('Creation of BaseResource instance', () => {
await expect(service.authHeaders.authorization()).resolves.toBe('Bearer 1234');
});

it('should accept a function oauthToken that returns a promise<string>', async () => {
it('should accept a dynamic oauthToken that returns a promise<string>', async () => {
const service = new BaseResource({
requesterFn: jest.fn(),
oauthToken: () => Promise.resolve('1234'),
oauthToken: () =>
new Promise((res) => {
setTimeout(() => {
res('1234');
}, 1000);
}),
});

expect(service.authHeaders.authorization).toBeFunction();
Expand Down
9 changes: 5 additions & 4 deletions packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
"scripts": {
"build": "tsup src/index.ts --format esm,cjs --dts --treeshake",
"test:types": "tsc",
"test:e2e:browser": "playwright test",
"test:e2e": "yarn test:e2e:browser",
"test:integration:nodejs": "jest --maxWorkers=50% test/integration/nodejs/resources/Issues.ts",
"test:integration": "yarn test:integration:nodejs",
"test:e2e:browser": "playwright test --project=e2e",
"test:e2e:nodejs": "jest --maxWorkers=50% test/e2e/nodejs",
"test:e2e": "yarn test:e2e:browser && yarn test:e2e:nodejs",
"test:integration:browser": "playwright test --project=integration",
"test:integration": "test:integration:browser",
"test:unit": "jest --maxWorkers=50% test/unit",
"format:docs": "prettier '**/(*.json|.yml|.js|.md)' --ignore-path ../../.prettierignore",
"format:docs:fix": "yarn format:docs --write",
Expand Down
36 changes: 26 additions & 10 deletions packages/rest/playwright.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import { defineConfig } from '@playwright/test';

const launchOptions = {
args: [
'--disable-web-security',
'--allow-file-access-from-files'
],
}

export default defineConfig({
use: {
browserName: 'chromium',
launchOptions: {
args: [
'--disable-web-security',
'--allow-file-access-from-files'
],
}
},
testDir: './test/e2e/browser',
testMatch: /.*.ts/,
testMatch: /.*.ts/,
reporter: [
['line'],
['junit', { outputFile: './reports/browser_junit.xml' }],
],
projects: [
{
name: 'e2e',
use: {
browserName: 'chromium',
launchOptions
},
testDir: './test/e2e/browser',
},
{
name: 'integration',
use: {
browserName: 'chromium',
launchOptions
},
testDir: './test/integration/browser',
}
]
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"xcase": "https://esm.sh/xcase?min",
"rate-limiter-flexible": "https://esm.sh/rate-limiter-flexible?min",
"picomatch-browser": "https://esm.sh/picomatch-browser?min",
"@gitbeaker/requester-utils": "../../../../../requester-utils/dist/index.mjs",
"@gitbeaker/core": "../../../../../core/dist/index.mjs"
"@gitbeaker/requester-utils": "../../../../requester-utils/dist/index.mjs",
"@gitbeaker/core": "../../../../core/dist/index.mjs"
}
}
</script>
<script type="module">
import * as gitbeaker from '../../../../dist/index.mjs'
import * as gitbeaker from '../../../dist/index.mjs'

// BAD PRACTISE!!! - Just for testing purposes
window.gitbeaker = gitbeaker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('Browser Import', () => {
].sort();

it('should import the Gitbeaker library though the global gitbeaker', async ({ page }) => {
const filepath = path.resolve(__dirname, 'assets', 'test-import.html');
const filepath = path.resolve(__dirname, '..', '..', 'assets', 'test-import.html');

await page.goto(`file://${filepath}`);

Expand Down
2 changes: 1 addition & 1 deletion packages/rest/test/e2e/browser/resources/Projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect, test as it } from '@playwright/test';
const { describe } = it;

const { GITLAB_PERSONAL_ACCESS_TOKEN = '', GITLAB_URL = '', TEST_ID = Date.now() } = process.env;
const htmlFilePath = path.resolve(__dirname, '..', 'assets', 'test-import.html');
const htmlFilePath = path.resolve(__dirname, '..', '..', 'assets', 'test-import.html');

describe('Projects API', () => {
it('should create a project', async ({ page }) => {
Expand Down
Loading

0 comments on commit ac69507

Please sign in to comment.