From ab1a683f1671f51d39aa17c5d6aa90fb5d1cc496 Mon Sep 17 00:00:00 2001 From: Florian PAUL Date: Thu, 27 Jul 2023 16:38:01 +0200 Subject: [PATCH] ci: test stuff --- .github/workflows/audit.yml | 37 -------- .github/workflows/code-check.yml | 74 ---------------- .github/workflows/codeql.yml | 61 -------------- .github/workflows/main.yml | 73 ---------------- .github/workflows/pr-labels.yml | 32 ------- .github/workflows/test-publish.yml | 84 +++++-------------- .verdaccio/README.md | 2 +- .verdaccio/conf/.npmrc | 2 +- .verdaccio/conf/config2.yaml | 53 ++++++++++++ package.json | 4 +- .../@o3r/test-helpers/src/create-test-app.ts | 4 +- packages/@o3r/test-helpers/src/verdaccio.ts | 2 +- 12 files changed, 79 insertions(+), 349 deletions(-) delete mode 100644 .github/workflows/audit.yml delete mode 100644 .github/workflows/code-check.yml delete mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/pr-labels.yml create mode 100644 .verdaccio/conf/config2.yaml diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml deleted file mode 100644 index b1d31b7bee..0000000000 --- a/.github/workflows/audit.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: NPM Audit - -concurrency: - group: ci-${{ github.ref }}-audit - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -on: - workflow_call: - push: - branches: - - main - - 'release/*' - pull_request: - branches: - - main - - 'release/*' - merge_group: - types: [checks_requested] - -jobs: - audit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup - uses: ./tools/github-actions/setup - - name: Audit - id: audit - uses: ./tools/github-actions/audit - with: - severity: critical - allWorkspaces: true - recursive: true - environment: all - - name: Summary - run: echo "${{ steps.audit.outputs.reportMarkdown }}" >> $GITHUB_STEP_SUMMARY - diff --git a/.github/workflows/code-check.yml b/.github/workflows/code-check.yml deleted file mode 100644 index 3db827c1b8..0000000000 --- a/.github/workflows/code-check.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Code check - -on: - workflow_call: - inputs: - affected: - type: boolean - required: false - default: false - description: Run test only on affective packages if true - secrets: - NX_CLOUD_ACCESS_TOKEN: - required: false - description: Token to use Nx Cloud token -jobs: - test: - strategy: - fail-fast: false - matrix: - os: [windows-latest, ubuntu-latest] - runs-on: ${{ matrix.os }} - env: - NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: ${{ inputs.affected && '0' || '1' }} - - name: Setup - uses: ./tools/github-actions/setup - - uses: ./.github/actions/setup-java - with: - install-jdk: 'true' - - name: Cache Jest - uses: actions/cache@v3 - env: - hash: ${{ hashFiles('package.json', 'tsconfig.base.json', 'tsconfig.build.json', 'nx.json') }} - with: - path: .cache/jest - key: ${{ runner.os }}-jest-${{ env.hash }} - restore-keys: | - ${{ runner.os }}-jest-${{ env.hash }} - ${{ runner.os }}-jest - ${{ runner.os }} - - name: Build swagger generator - run: yarn nx run ama-sdk-generator-sdk:build-swagger - - name: Test - env: - testCmd: ${{ inputs.affected && format('test:affected --base=remotes/origin/{0}', github.base_ref || github.ref_name) || 'test'}} - run: yarn ${{ env.testCmd }} - lint: - runs-on: ubuntu-latest - env: - NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: ${{ inputs.affected && '0' || '1' }} - - name: Setup - uses: ./tools/github-actions/setup - - name: Cache Eslint - uses: actions/cache@v3 - with: - path: .cache/eslint - key: ${{ runner.os }}-eslint-${{ hashFiles('yarn.lock') }} - restore-keys: | - ${{ runner.os }}-eslint-${{ env.hash }} - ${{ runner.os }}-eslint - ${{ runner.os }} - - name: Dependency Check - run: yarn in-source-dep-check --fail-on-error - - name: Lint - env: - lintCmd: ${{ inputs.affected && format('lint:affected --base=remotes/origin/{0}', github.base_ref || github.ref_name) || 'lint'}} - run: yarn ${{ env.lintCmd }} --configuration ci diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index 37368e1840..0000000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,61 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: - - main - - 'release/*' - pull_request: - branches: - - main - - 'release/*' - merge_group: - types: [checks_requested] - - schedule: - - cron: '31 2 * * 6' - -jobs: - analyze: - name: Analyze - runs-on: 'ubuntu-latest' - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: - - javascript - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - config-file: ./.github/codeql/codeql-config.yml - - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a05a0b8a63..2552c8676d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,80 +17,7 @@ on: types: [checks_requested] jobs: - build: - runs-on: ubuntu-latest - env: - NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - steps: - - uses: actions/checkout@v3 - - uses: ./tools/github-actions/setup - - uses: ./.github/actions/setup-java - with: - install-jdk: 'true' - - run: yarn build:swagger-gen - - run: yarn build - - uses: ./tools/github-actions/upload-build-output - - version: - permissions: - contents: write - runs-on: ubuntu-latest - outputs: - nextVersionTag: ${{ steps.newVersion.outputs.nextVersionTag }} - isPreRelease: ${{ contains( steps.newVersion.outputs.nextVersionTag, '-' ) || github.event_name == 'pull_request' || github.event_name == 'merge_group'}} - steps: - - uses: actions/checkout@v3 - - uses: ./tools/github-actions/setup - - name: New Version - id: newVersion - uses: ./tools/github-actions/new-version - with: - defaultBranch: main - defaultBranchPrereleaseName: alpha - - name: Create release - if: github.event_name != 'pull_request' && github.event_name != 'merge_group' - run: gh release create v${{ steps.newVersion.outputs.nextVersionTag }} --generate-notes ${{ contains( steps.newVersion.outputs.nextVersionTag, '-' ) && '--prerelease' || '' }} --target ${{ github.ref_name }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - checks: - uses: ./.github/workflows/code-check.yml - secrets: - NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - with: - affected: ${{ github.event_name == 'pull_request' }} - test-publish: uses: ./.github/workflows/test-publish.yml secrets: NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - needs: [build] - - publish-packages: - uses: ./.github/workflows/publish.yml - if: ${{ github.event_name != 'pull_request' && github.event_name != 'merge_group' }} - permissions: - packages: write - contents: read - secrets: inherit - needs: [version, build, checks, test-publish] - with: - version: ${{ needs.version.outputs.nextVersionTag }} - prerelease: ${{ needs.version.outputs.isPreRelease == 'true' }} - isPullRequest: false - - documentation-main: - secrets: inherit - needs: [version, build, checks] - if: ${{ github.event_name != 'pull_request' && github.event_name != 'merge_group' && github.ref_name == 'main' }} - uses: ./.github/workflows/documentation.yml - with: - version: ${{ needs.version.outputs.nextVersionTag }} - documentation-pr: - secrets: inherit - needs: [version] - if: ${{ (github.event_name == 'pull_request' && github.base_ref == 'main') || github.event_name == 'merge_group' }} - uses: ./.github/workflows/documentation.yml - with: - version: ${{ needs.version.outputs.nextVersionTag }} - shouldDeploy: false diff --git a/.github/workflows/pr-labels.yml b/.github/workflows/pr-labels.yml deleted file mode 100644 index 487633395d..0000000000 --- a/.github/workflows/pr-labels.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Pull Request Label - -on: pull_request - -jobs: - setup-label: - runs-on: ubuntu-latest - env: - NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - permissions: - pull-requests: write - steps: - - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: Setup - uses: ./tools/github-actions/setup - - run: | - LABELS="$(yarn pr-labels "$(git log -1 --pretty=%B || echo '')")" - echo "LABELS=$LABELS" >> $GITHUB_ENV - - uses: actions/github-script@v6 - if: env.LABELS != '[]' - continue-on-error: true - with: - script: | - const [owner, repo] = '${{ github.repository }}'.split('/'); - github.rest.issues.addLabels({ - owner, - repo, - issue_number: context.issue.number, - labels: ${{ env.LABELS }} - }) diff --git a/.github/workflows/test-publish.yml b/.github/workflows/test-publish.yml index 2b29ff7bce..b3d3df0ed7 100644 --- a/.github/workflows/test-publish.yml +++ b/.github/workflows/test-publish.yml @@ -12,78 +12,32 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] - packageManager: [yarn, npm] + os: [windows-2019] + packageManager: [yarn] runs-on: ${{ matrix.os }} env: NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} ENFORCED_PACKAGE_MANAGER: ${{ matrix.packageManager }} steps: - uses: actions/checkout@v3 - - uses: ./tools/github-actions/download-build-output - - uses: ./tools/github-actions/setup - - uses: ./.github/actions/setup-java - with: - install-jdk: 'true' - - name: Get current month to build the cache key - run: echo "currentMonth=$(date +'%Y-%m')" >> $GITHUB_ENV - shell: bash - - name: Cache test-app yarn - uses: actions/cache@v3 - with: - path: | - .cache/test-app - !.cache/test-app/@ama-sdk* - !.cache/test-app/@ama-terasu* - !.cache/test-app/@o3r* - key: ${{ runner.os }}-test-app-${{ matrix.packageManager }}-${{ env.currentMonth }} - - name: Cache test-sdk yarn - uses: actions/cache@v3 - with: - path: | - .cache/test-sdk - !.cache/test-sdk/@ama-sdk* - !.cache/test-sdk/@ama-terasu* - !.cache/test-sdk/@o3r* - key: ${{ runner.os }}-test-sdk-${{ matrix.packageManager }}-${{ env.currentMonth }} - name: Setup verdaccio once for all tests id: setup-verdaccio run: | - mkdir ./.verdaccio/storage - chmod a+rwx -R ./.verdaccio/storage - yarn verdaccio:start-persistent - yarn verdaccio:publish + # This is working, but blocks execution : + # npx --yes verdaccio --config $GITHUB_WORKSPACE\\.verdaccio\\conf\\config2.yaml + + # This ain't doin' shit + # start /B "" "npx --yes verdaccio --config $GITHUB_WORKSPACE\\.verdaccio\\conf\\config2.yaml" + + # Also shit + # cmd /C "npx --yes verdaccio --config $GITHUB_WORKSPACE\\.verdaccio\\conf\\config2.yaml" + + # Garbage + # cmd /C "start /B npx --yes verdaccio --config $GITHUB_WORKSPACE\\.verdaccio\\conf\\config2.yaml" + + start /B "" npx --yes verdaccio --config $GITHUB_WORKSPACE\\.verdaccio\\conf\\config2.yaml + yarn install + npx --yes wait-on http://127.0.0.1:4873 -t 180000 + yarn verdaccio:login shell: bash - - name: Test - id: it-tests - run: yarn test-int --output-style=stream - - name: Zip verdaccio storage on failure - if: failure() && (steps.setup-verdaccio.conclusion == 'failure' || steps.it-tests.conclusion == 'failure') - run: zip -r verdaccio.zip ./.verdaccio - - name: Zip generated app on failure - if: failure() && steps.it-tests.conclusion == 'failure' - run: | - mkdir -p ./otter - cp -R ./.cache ./otter/.cache - zip -r it-tests.zip ../it-tests ./otter/.cache -x "./otter/.cache/nx/*" -x "../it-tests/*/node_modules/*" - - name: Publish verdaccio storage on failure - if: failure() && (steps.setup-verdaccio.conclusion == 'failure' || steps.it-tests.conclusion == 'failure') - uses: actions/upload-artifact@v3 - with: - name: verdaccio-${{ matrix.os }}-${{ matrix.packageManager }} - path: verdaccio.zip - - name: Publish generated tests environment on failure - if: failure() && steps.it-tests.conclusion == 'failure' - uses: actions/upload-artifact@v3 - with: - name: it-tests-${{ matrix.os }}-${{ matrix.packageManager }} - path: it-tests.zip - - name: Publish tests reports - if: always() - uses: actions/upload-artifact@v3 - with: - name: it-reports-${{ matrix.os }}-${{ matrix.packageManager }} - path: 'packages/**/dist-test/it-report.xml' - - name: Stop verdaccio - if: always() - run: yarn verdaccio:stop + timeout-minutes: 10 diff --git a/.verdaccio/README.md b/.verdaccio/README.md index e37fba5a20..b756fa4dd4 100644 --- a/.verdaccio/README.md +++ b/.verdaccio/README.md @@ -24,4 +24,4 @@ docker ps -a -q --filter="name=verdaccio" | xargs docker container stop ## How to use -Add `registry=http://localhost:4873` in your `.npmrc` / `yarnrc.yml` files or as a parameter of the install command +Add `registry=http://127.0.0.1:4873` in your `.npmrc` / `yarnrc.yml` files or as a parameter of the install command diff --git a/.verdaccio/conf/.npmrc b/.verdaccio/conf/.npmrc index c18594274e..d5231db0b7 100644 --- a/.verdaccio/conf/.npmrc +++ b/.verdaccio/conf/.npmrc @@ -1 +1 @@ -registry=http://localhost:4873 +registry=http://127.0.0.1:4873 diff --git a/.verdaccio/conf/config2.yaml b/.verdaccio/conf/config2.yaml new file mode 100644 index 0000000000..f7d43b66f8 --- /dev/null +++ b/.verdaccio/conf/config2.yaml @@ -0,0 +1,53 @@ +# +# This is the default configuration file. As it allows all users to do anything, +# please read carefully the documentation and best practices to improve security. +# +# Do not configure host and port under `listen` in this file +# as it will be ignored when using docker. +# see https://verdaccio.org/docs/en/docker#docker-and-custom-port-configuration +# +# Look here for more config file examples: +# https://github.com/verdaccio/verdaccio/blob/5.x/conf/docker.yaml +# +# Read about the best practices +# https://verdaccio.org/docs/best + +storage: ../storage + +plugins: ../plugins + +web: + title: Verdaccio + +auth: + htpasswd: + file: ../storage/htpasswd + algorithm: bcrypt + +uplinks: + npmjs: + url: https://registry.npmjs.org/ + +packages: + '**': + access: $all + publish: $authenticated + unpublish: $authenticated + proxy: npmjs + '@o3r/*': + proxy: no-proxy + '@ama-sdk/*': + proxy: no-proxy + '@ama-terasu/*': + proxy: no-proxy + +no_proxy: localhost,127.0.0.1 + +server: + keepAliveTimeout: 60 + +max_body_size: 100mb + +middlewares: + audit: + enabled: true diff --git a/package.json b/package.json index 7dfa690030..a9fd088f11 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,8 @@ "verdaccio:start": "docker run -d -it --rm --name verdaccio -p 4873:4873 -v \"$(shx pwd)/.verdaccio/conf\":/verdaccio/conf verdaccio/verdaccio", "verdaccio:start-persistent": "docker run -d -it --rm --name verdaccio -p 4873:4873 -v \"$(shx pwd)/.verdaccio/conf\":/verdaccio/conf -v \"$(shx pwd)/.verdaccio/storage\":/verdaccio/storage:z verdaccio/verdaccio", "verdaccio:clean": "rimraf ./.verdaccio/storage", - "verdaccio:login": "yarn cpy --cwd=./.verdaccio/conf .npmrc . --rename=.npmrc-logged && npx --yes npm-cli-login -u verdaccio -p verdaccio -e test@test.com -r http://localhost:4873 --config-path \".verdaccio/conf/.npmrc-logged\"", - "verdaccio:publish": "yarn set:version 999.0.0 --include \"!**/!(dist)/package.json\" --include !package.json && yarn verdaccio:login && yarn run publish --userconfig \".verdaccio/conf/.npmrc-logged\" --tag=latest --@o3r:registry=http://localhost:4873 --@ama-sdk:registry=http://localhost:4873", + "verdaccio:login": "yarn cpy --cwd=./.verdaccio/conf .npmrc . --rename=.npmrc-logged && npx --yes npm-cli-login -u verdaccio -p verdaccio -e test@test.com -r http://127.0.0.1:4873 --config-path \".verdaccio/conf/.npmrc-logged\"", + "verdaccio:publish": "yarn set:version 999.0.0 --include \"!**/!(dist)/package.json\" --include !package.json && yarn verdaccio:login && yarn run publish --userconfig \".verdaccio/conf/.npmrc-logged\" --tag=latest --@o3r:registry=http://127.0.0.1:4873 --@ama-sdk:registry=http://127.0.0.1:4873", "verdaccio:stop": "docker container stop $(docker ps -a -q --filter=\"name=verdaccio\")", "watch:vscode-extension": "yarn nx run vscode-extension:compile:watch", "workspaces:list": "yarn workspaces list --no-private --json | shx sed \"s/.*\\\"location\\\":\\\"(.*?)\\\".*/\\$1/\"" diff --git a/packages/@o3r/test-helpers/src/create-test-app.ts b/packages/@o3r/test-helpers/src/create-test-app.ts index 64797f278d..498c7db89a 100644 --- a/packages/@o3r/test-helpers/src/create-test-app.ts +++ b/packages/@o3r/test-helpers/src/create-test-app.ts @@ -66,7 +66,7 @@ export async function createTestApp(inputOptions: Partial) appDirectory: 'test-app', cwd: process.cwd(), globalFolderPath: process.cwd(), - registry: 'http://localhost:4873', + registry: 'http://127.0.0.1:4873', blank: false, ...inputOptions }; @@ -135,7 +135,7 @@ export async function createTestApp(inputOptions: Partial) execSync('yarn config set nodeLinker pnp', execAppOptions); execSync(`yarn config set npmScopes.ama-sdk.npmRegistryServer ${options.registry}`, execAppOptions); execSync(`yarn config set npmScopes.o3r.npmRegistryServer ${options.registry}`, execAppOptions); - execSync('yarn config set unsafeHttpWhitelist localhost', execAppOptions); + execSync('yarn config set unsafeHttpWhitelist 127.0.0.1', execAppOptions); } else { // FIXME to be removed? execSync('npm config set legacy-peer-deps=true -L project', execAppOptions); diff --git a/packages/@o3r/test-helpers/src/verdaccio.ts b/packages/@o3r/test-helpers/src/verdaccio.ts index 3f7ce85bdb..d6ffcb8e8c 100644 --- a/packages/@o3r/test-helpers/src/verdaccio.ts +++ b/packages/@o3r/test-helpers/src/verdaccio.ts @@ -6,7 +6,7 @@ import pidFromPort from 'pid-from-port'; /** * Set up a local npm registry inside a docker image before the tests. * Publish all the packages of the Otter monorepo on it. - * Can be accessed during the tests with url http://localhost:4873 + * Can be accessed during the tests with url http://127.0.0.1:4873 */ export function setupLocalRegistry() { let shouldHandleVerdaccio = false;