From fc1954e2c5146d21325645dc6fecd143d041d331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=89=B2?= Date: Sun, 31 Dec 2023 21:39:05 +0800 Subject: [PATCH] ci: upgrade to GHA (#1747) --- .github/workflows/ci.yml | 117 ++++++++++++++ azure-pipelines.yml | 150 ------------------ .../github-comment.js => github/comment.js} | 4 +- src/app/app.config.ts | 4 +- src/app/layout/header/header.component.html | 22 ++- src/app/routes/home/home.component.html | 12 +- 6 files changed, 141 insertions(+), 168 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 azure-pipelines.yml rename scripts/{azure/github-comment.js => github/comment.js} (92%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..ced5c24433 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,117 @@ +name: CI + +on: push + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: jwalton/gh-find-current-pr@v1 + id: findPr + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + - name: Comment on github + run: node ./scripts/github/comment.js "[Preview Preparing...](https://github.com/ng-alain/delon/actions/runs/${{ github.run_id }})" + env: + ACCESS_REPO: ${{ github.repository }} + ACCESS_TOKEN: ${{ secrets.CI_TOKEN }} + PR_NUMBER: ${{ steps.findPr.outputs.pr }} + - uses: actions/cache@v3 + with: + path: ./node_modules + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/*.patch') }} + - name: Install node modules + run: yarn install --frozen-lockfile + - name: Build artifacts + run: ./scripts/ci/build-artifacts.sh + env: + ACCESS_TOKEN: ${{ secrets.CI_TOKEN }} + - name: Build site + run: yarn run site:build + - name: 'Deploy Site' + run: | + export DEPLOY_DOMAIN=https://preview-${{ steps.findPr.outputs.pr }}-ng-alain-delon.surge.sh + echo "Deploy to $DEPLOY_DOMAIN" + cp ./src/dist/browser/index.html ./src/dist/browser/404.html + npx surge --project ./src/dist/browser --domain $DEPLOY_DOMAIN + env: + ACCESS_REPO: ${{ github.repository }} + ACCESS_TOKEN: ${{ secrets.CI_TOKEN }} + SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + - name: 'Update comment on github' + run: | + export DEPLOY_DOMAIN=https://preview-${{ steps.findPr.outputs.pr }}-ng-alain-delon.surge.sh + node ./scripts/github/comment.js "[Preview is ready!]($DEPLOY_DOMAIN)" + env: + ACCESS_REPO: ${{ github.repository }} + ACCESS_TOKEN: ${{ secrets.CI_TOKEN }} + PR_NUMBER: ${{ steps.findPr.outputs.pr }} + - name: 'When failed' + if: failure() + run: node ./scripts/github/comment.js "[Preview Build Failed!](https://github.com/ng-alain/delon/actions/runs/${{ github.run_id }})" + env: + ACCESS_REPO: ${{ github.repository }} + ACCESS_TOKEN: ${{ secrets.CI_TOKEN }} + PR_NUMBER: ${{ steps.findPr.outputs.pr }} + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + - uses: actions/cache@v3 + with: + path: ./node_modules + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/*.patch') }} + - name: Install node modules + run: yarn install --frozen-lockfile + - name: Test + run: yarn run test + - uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + directory: ./coverage/ + files: cobertura-coverage.xml + fail_ci_if_error: true + verbose: true + + test-cli: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + - uses: actions/cache@v3 + with: + path: ./node_modules + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/*.patch') }} + - name: Install node modules + run: yarn install --frozen-lockfile + - name: Test + run: yarn run test:cli + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version-file: '.nvmrc' + cache: 'yarn' + - uses: actions/cache@v3 + with: + path: ./node_modules + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/*.patch') }} + - name: Install node modules + run: yarn install --frozen-lockfile + - name: Check code lint + run: yarn run lint diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index c15f50247d..0000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,150 +0,0 @@ -name: ng-alain-delon - -trigger: - - master - -pool: - vmImage: 'ubuntu-latest' - -stages: - - stage: env - jobs: - - job: Nodes - steps: - - task: NodeTool@0 - inputs: - versionSource: 'fromFile' - versionFilePath: '.nvmrc' - displayName: 'Install Node.js' - - - stage: build - jobs: - - job: build - steps: - - task: NodeTool@0 - inputs: - versionSource: 'fromFile' - versionFilePath: '.nvmrc' - displayName: 'Install Node.js' - - script: | - node --version - yarn --version - yarn install - displayName: 'Install' - - task: Bash@3 - env: - ACCESS_TOKEN: $(ACCESS_TOKEN) - inputs: - targetType: 'filePath' - filePath: 'scripts/ci/build-artifacts.sh' - displayName: 'Build artifacts' - - script: | - node ./scripts/azure/github-comment.js "[Preview Preparing...](https://dev.azure.com/ng-alain/delon/_build/results?buildId=$(Build.BuildId))" - displayName: 'Comment on github' - env: - ACCESS_REPO: $(ACCESS_REPO) - ACCESS_TOKEN: $(ACCESS_TOKEN) - - script: | - yarn run site:build - displayName: 'Build site' - - script: | - export DEPLOY_DOMAIN=https://preview-${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}-ng-alain-delon.surge.sh - echo "Deploy to $DEPLOY_DOMAIN" - cp ./src/dist/browser/index.html ./src/dist/browser/404.html - npx surge --project ./src/dist/browser --domain $DEPLOY_DOMAIN - displayName: 'Deploy Site' - env: - ACCESS_REPO: $(ACCESS_REPO) - ACCESS_TOKEN: $(ACCESS_TOKEN) - SURGE_LOGIN: $(SURGE_LOGIN) - SURGE_TOKEN: $(SURGE_TOKEN) - - script: | - export DEPLOY_DOMAIN=https://preview-${SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}-ng-alain-delon.surge.sh - node ./scripts/azure/github-comment.js "[Preview is ready!]($DEPLOY_DOMAIN)" - displayName: 'Update comment on github' - env: - ACCESS_REPO: $(ACCESS_REPO) - ACCESS_TOKEN: $(ACCESS_TOKEN) - - job: Build_Failed - dependsOn: Build - condition: failed() - steps: - - task: NodeTool@0 - inputs: - versionSource: 'fromFile' - versionFilePath: '.nvmrc' - displayName: 'Install Node.js' - - checkout: self - displayName: 'Checkout' - clean: true - fetchDepth: 1 - - script: yarn install - displayName: 'Install modules' - - script: | - node ./scripts/azure/github-comment.js "[Preview Failed](https://dev.azure.com/ng-alain/delon/_build/results?buildId=$(Build.BuildId))" - displayName: 'Comment on github' - env: - ACCESS_REPO: $(ACCESS_REPO) - ACCESS_TOKEN: $(ACCESS_TOKEN) - dependsOn: env - - - stage: test - jobs: - - job: packages - steps: - - task: NodeTool@0 - inputs: - versionSource: 'fromFile' - versionFilePath: '.nvmrc' - displayName: 'Install Node.js' - - script: yarn install - displayName: 'Install' - - script: | - yarn run test - cat ./coverage/lcov.info | ./node_modules/.bin/codecov - env: - CODECOV_TOKEN: $(CODECOV_TOKEN) - - - task: PublishCodeCoverageResults@1 - displayName: 'publish code coverage results' - condition: succeededOrFailed() - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml - reportDirectory: $(System.DefaultWorkingDirectory)/coverage - failIfCoverageEmpty: true - - - task: PublishTestResults@2 - displayName: 'publish test results' - condition: succeededOrFailed() - inputs: - searchFolder: $(System.DefaultWorkingDirectory)/junit - failTaskOnFailedTests: true - testRunTitle: DELON - testResultsFormat: JUnit - testResultsFiles: '**/TESTS*.xml' - - job: cli - steps: - - task: NodeTool@0 - inputs: - versionSource: 'fromFile' - versionFilePath: '.nvmrc' - displayName: 'Install Node.js' - - script: yarn install - displayName: 'Install' - - script: yarn run test:cli - dependsOn: env - - - stage: lint - jobs: - - job: packages - steps: - - task: NodeTool@0 - inputs: - versionSource: 'fromFile' - versionFilePath: '.nvmrc' - displayName: 'Install Node.js' - - script: yarn install - displayName: 'Install' - - script: yarn run lint - dependsOn: env diff --git a/scripts/azure/github-comment.js b/scripts/github/comment.js similarity index 92% rename from scripts/azure/github-comment.js rename to scripts/github/comment.js index d1a4595e2a..3b9c78502d 100644 --- a/scripts/azure/github-comment.js +++ b/scripts/github/comment.js @@ -1,7 +1,7 @@ const REPO = process.env.ACCESS_REPO; const TOKEN = process.env.ACCESS_TOKEN; -const PR = process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER; -const REPLACE_MARK = ''; +const PR = process.env.PR_NUMBER; +const REPLACE_MARK = ''; const argv = process.argv; diff --git a/src/app/app.config.ts b/src/app/app.config.ts index f230a1ccec..533005b5d2 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -2,7 +2,7 @@ import { provideHttpClient, withFetch, withInterceptors } from '@angular/common/ import ngLang from '@angular/common/locales/zh'; import { APP_ID, ApplicationConfig, ErrorHandler, importProvidersFrom } from '@angular/core'; import { provideAnimations } from '@angular/platform-browser/animations'; -import { provideRouter, withComponentInputBinding } from '@angular/router'; +import { provideRouter, withComponentInputBinding, withInMemoryScrolling } from '@angular/router'; import { ServiceWorkerModule } from '@angular/service-worker'; import { provideNuMonacoEditorConfig } from '@ng-util/monaco-editor'; @@ -92,7 +92,7 @@ export const appConfig: ApplicationConfig = { { provide: APP_ID, useValue: 'ngAlainDoc' }, provideHttpClient(withFetch(), withInterceptors([mockInterceptor])), provideAnimations(), - provideRouter(routes, withComponentInputBinding()), + provideRouter(routes, withComponentInputBinding(), withInMemoryScrolling({ scrollPositionRestoration: 'top' })), // provideClientHydration(), // 暂时不开启水合,除了编译时间长,还有就是对DOM要求比较高 provideAlain({ config: alainConfig, defaultLang, i18nClass: I18NService }), provideNzConfig(ngZorroConfig), diff --git a/src/app/layout/header/header.component.html b/src/app/layout/header/header.component.html index 920f839a43..37f4b05ecd 100644 --- a/src/app/layout/header/header.component.html +++ b/src/app/layout/header/header.component.html @@ -62,18 +62,16 @@ }
-

- -

+