From f2ab4c4b60747b311ee0234de3909bb846ed869d Mon Sep 17 00:00:00 2001 From: YANG QIA <2013xile@gmail.com> Date: Mon, 9 Sep 2024 10:15:53 +0800 Subject: [PATCH] chore: optimize ci (#5233) * fix(ci): optimize release next ci * chore: update * chore: update * chore: update * chore: update * chore: add manual-build-pro-plugin-image.yml --- .github/workflows/changelog-and-release.yml | 10 +- .../manual-build-pro-plugin-image.yml | 109 ++++++++++++++++++ .github/workflows/release-next.yml | 42 ++++--- scripts/release/changelogAndRelease.js | 9 +- 4 files changed, 149 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/manual-build-pro-plugin-image.yml diff --git a/.github/workflows/changelog-and-release.yml b/.github/workflows/changelog-and-release.yml index d57889e63..7b9b6f2f4 100644 --- a/.github/workflows/changelog-and-release.yml +++ b/.github/workflows/changelog-and-release.yml @@ -6,6 +6,14 @@ concurrency: on: workflow_dispatch: + inputs: + version: + type: choice + description: Please choose a version + options: + - beta + - alpha + default: beta push: tags: - 'v*-beta' @@ -62,7 +70,7 @@ jobs: - name: Run script shell: bash run: | - node scripts/release/changelogAndRelease.js + node scripts/release/changelogAndRelease.js --ver ${{ inputs.version }} env: PRO_PLUGIN_REPOS: ${{ vars.PRO_PLUGIN_REPOS }} GH_TOKEN: ${{ steps.app-token.outputs.token }} diff --git a/.github/workflows/manual-build-pro-plugin-image.yml b/.github/workflows/manual-build-pro-plugin-image.yml new file mode 100644 index 000000000..2ca342f11 --- /dev/null +++ b/.github/workflows/manual-build-pro-plugin-image.yml @@ -0,0 +1,109 @@ +name: Build Pro Plugin Docker Image + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + workflow_dispatch: + inputs: + pro_plugin: + description: 'Please enter a pro plugin name' + required: true + pr_number: + description: 'Please enter the pr number of pro plugin repository' + required: false +jobs: + build-and-push: + runs-on: ubuntu-latest + services: + verdaccio: + image: verdaccio/verdaccio:latest + ports: + - 4873:4873 + steps: + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ vars.NOCOBASE_APP_ID }} + private-key: ${{ secrets.NOCOBASE_APP_PRIVATE_KEY }} + repositories: nocobase,pro-plugins,${{ join(fromJSON(vars.NEXT_PRO_PLUGIN_REPOS), ',') }},${{ join(fromJSON(vars.CUSTOM_PRO_PLUGIN_REPOS), ',') }} + skip-token-revoke: true + - name: Checkout nocobase/nocobase + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref || github.ref_name }} + fetch-depth: 0 + - name: Checkout plugin + uses: actions/checkout@v3 + with: + repository: nocobase/plugin-${{ inputs.pro_plugin }} + path: packages/pro-plugins/@nocobase/plugin-${{ inputs.pro_plugin }} + - name: Checkout pr + shell: bash + run: | + cd ./packages/pro-plugins/@nocobase/plugin-${{ inputs.pro_plugin }} + gh pr checkout ${{ inputs.pr_number }} + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + - name: rm .git + run: rm -rf packages/pro-plugins/@nocobase/plugin-${{ inputs.pro_plugin }}/.git && git config --global user.email "you@example.com" && git config --global user.name "Your Name" && git add -A && git commit -m "tmp commit" + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + driver-opts: network=host + - name: Login to Aliyun Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ secrets.ALI_DOCKER_REGISTRY }} + username: ${{ secrets.ALI_DOCKER_USERNAME }} + password: ${{ secrets.ALI_DOCKER_PASSWORD }} + - name: Set tags + id: set-tags + run: | + echo "::set-output name=tags::${{ secrets.ALI_DOCKER_REGISTRY }}/pr-${{ inputs.pr_number }}-${{ inputs.pro_plugin }}" + - name: IMAGE_TAG + env: + IMAGE_TAG: pr-${{ inputs.pr_number }} + run: | + echo $IMAGE_TAG + - name: Set variables + run: | + target_directory="./packages/pro-plugins/@nocobase" + subdirectories=$(find "$target_directory" -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | tr '\n' ' ') + trimmed_variable=$(echo "$subdirectories" | xargs) + packageNames="@nocobase/${trimmed_variable// / @nocobase/}" + pluginNames="${trimmed_variable//plugin-/}" + BEFORE_PACK_NOCOBASE="yarn add $packageNames -W" + APPEND_PRESET_LOCAL_PLUGINS="${pluginNames// /,}" + echo "var1=$BEFORE_PACK_NOCOBASE" >> $GITHUB_OUTPUT + echo "var2=$APPEND_PRESET_LOCAL_PLUGINS" >> $GITHUB_OUTPUT + id: vars + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + file: Dockerfile + build-args: | + VERDACCIO_URL=http://localhost:4873/ + COMMIT_HASH=${GITHUB_SHA} + PLUGINS_DIRS=pro-plugins + BEFORE_PACK_NOCOBASE=${{ steps.vars.outputs.var1 }} + APPEND_PRESET_LOCAL_PLUGINS=${{ steps.vars.outputs.var2 }} + push: true + tags: ${{ steps.set-tags.outputs.tags }} + - name: Deploy NocoBase + env: + IMAGE_TAG: pr-${{ inputs.pr_number }} + run: | + echo $IMAGE_TAG + export APP_NAME=$(echo $IMAGE_TAG | cut -d ":" -f 2)-${{ inputs.pro_plugin }} + echo $APP_NAME + curl --retry 2 --location --request POST "${{secrets.NOCOBASE_DEPLOY_HOST}}$APP_NAME" \ + --header 'Content-Type: application/json' \ + -d "{ + \"tag\": \"$APP_NAME\", + \"dialect\": \"postgres\" + }" diff --git a/.github/workflows/release-next.yml b/.github/workflows/release-next.yml index bcb770fae..61264465d 100644 --- a/.github/workflows/release-next.yml +++ b/.github/workflows/release-next.yml @@ -28,6 +28,7 @@ jobs: uses: actions/checkout@v4 with: ref: next + fetch-depth: 0 - name: Send curl request and parse response env: PKG_USERNAME: ${{ secrets.PKG_USERNAME }} @@ -87,8 +88,6 @@ jobs: yarn config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} yarn install yarn lerna version ${{ env.NEWVERSION }} -y --no-git-tag-version - git tag v${{ env.NEWVERSION }} - git push origin v${{ env.NEWVERSION }} yarn build echo "# test" >> Release.md git add . @@ -101,6 +100,7 @@ jobs: repository: nocobase/pro-plugins path: packages/pro-plugins ref: next + fetch-depth: 0 token: ${{ steps.app-token.outputs.token }} - name: Clone pro repos shell: bash @@ -109,19 +109,6 @@ jobs: do git clone -b next https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/nocobase/$repo.git packages/pro-plugins/@nocobase/$repo done - - name: Tag Pro plugins - run: | - cd ./packages/pro-plugins - git tag v${{ env.NEWVERSION }} - git push origin v${{ env.NEWVERSION }} - cd ../../ - for repo in ${{ join(fromJSON(vars.NEXT_PRO_PLUGIN_REPOS), ' ') }} ${{ join(fromJSON(vars.CUSTOM_PRO_PLUGIN_REPOS), ' ') }} - do - cd ./packages/pro-plugins/@nocobase/$repo - git tag v${{ env.NEWVERSION }} - git push origin v${{ env.NEWVERSION }} - cd ../../../../ - done - name: Build Pro plugins run: | yarn config set registry https://registry.npmjs.org/ @@ -132,17 +119,36 @@ jobs: run: | git reset --hard npm config set //pkg.nocobase.com/:_authToken=${{ env.PKG_NOCOBASE_TOKEN }} - yarn release:force --no-verify-access --no-git-reset --registry https://pkg.nocobase.com --dist-tag=next + # yarn release:force --no-verify-access --no-git-reset --registry https://pkg.nocobase.com --dist-tag=next - name: publish pkg-src.nocobase.com run: | git reset --hard bash generate-npmignore.sh ignore-src npm config set //pkg-src.nocobase.com/:_authToken=${{ env.PKG_SRC_NOCOBASE_TOKEN }} yarn release:force --no-verify-access --no-git-reset --registry https://pkg-src.nocobase.com --dist-tag=next - - name: Run script + - name: Tag + run: | + git reset --hard HEAD~ + git tag v${{ env.NEWVERSION }} + git push origin v${{ env.NEWVERSION }} + cd ./packages/pro-plugins + git reset --hard + git tag v${{ env.NEWVERSION }} + git push origin v${{ env.NEWVERSION }} + cd ../../ + for repo in ${{ join(fromJSON(vars.NEXT_PRO_PLUGIN_REPOS), ' ') }} ${{ join(fromJSON(vars.CUSTOM_PRO_PLUGIN_REPOS), ' ') }} + do + cd ./packages/pro-plugins/@nocobase/$repo + git reset --hard + git tag v${{ env.NEWVERSION }} + git push origin v${{ env.NEWVERSION }} + cd ../../../../ + done + - name: Run release script shell: bash run: | - node scripts/release/changelogAndRelease.js --ver alpha + git fetch + node scripts/release/changelogAndRelease.js --ver alpha --test env: PRO_PLUGIN_REPOS: ${{ vars.NEXT_PRO_PLUGIN_REPOS }} GH_TOKEN: ${{ steps.app-token.outputs.token }} diff --git a/scripts/release/changelogAndRelease.js b/scripts/release/changelogAndRelease.js index b3ea6a4b7..73c3255e3 100644 --- a/scripts/release/changelogAndRelease.js +++ b/scripts/release/changelogAndRelease.js @@ -4,7 +4,7 @@ const path = require('path'); const { Command } = require('commander'); const program = new Command(); -program.option('-f, --from [from]').option('-t, --to [to]').option('-v, --ver [ver]'); +program.option('-f, --from [from]').option('-t, --to [to]').option('-v, --ver [ver]').option('--test'); program.parse(process.argv); const header = { @@ -345,11 +345,16 @@ async function createRelease(cn, en, to) { } async function writeChangelogAndCreateRelease() { - let { ver = 'beta' } = program.opts(); + let { ver = 'beta', test } = program.opts(); const { cn, en, from, to } = await generateChangelog(); if (!cn && !en) { throw new Error('No changelog generated'); } + if (test) { + console.log(en); + console.log(cn); + return; + } if (ver === 'beta') { await writeChangelog(cn, en, from, to); }