From 68061a5d291d9b91a4f4fd93171e516fabba1f3a Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 19 Feb 2022 16:10:32 +0800 Subject: [PATCH 1/2] refactor: github actions & nightly-build Signed-off-by: Wing-Kam Wong --- .github/workflows/release-docker.yml | 34 +++++++++++-- .github/workflows/release-nightly-dev.yml | 59 +++++++++++++++++++++++ .github/workflows/release-nocodb.yml | 7 +++ .github/workflows/release-npm.yml | 34 ++++++++++--- packages/nc-gui/nuxt.config.js | 9 +++- packages/nc-gui/package.json | 2 +- scripts/upgradeNcGui.js | 44 ++++++++++++++--- 7 files changed, 170 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/release-nightly-dev.yml diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index 1efc14d9ba..6f76486d38 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -7,13 +7,29 @@ on: tag: description: "Docker image tag" required: true - # Triggered by release-nocodb.yml + targetEnv: + description: "Target Environment" + required: true + type: choice + options: + - DEV + - PROD + # Triggered by release-nocodb.yml / release-nightly-dev.yml workflow_call: inputs: tag: description: "Docker image tag" required: true type: string + targetEnv: + description: "Target Environment" + required: true + type: string + secrets: + DOCKERHUB_USERNAME: + required: true + DOCKERHUB_TOKEN: + required: true jobs: buildx: @@ -24,6 +40,18 @@ jobs: matrix: node-version: [12] steps: + - name: Get Docker Repository + id: get-docker-repository + run: | + DOCKER_REPOSITORY=nocodb + if [[ ${{ github.event.inputs.targetEnv || inputs.targetEnv }} == 'DEV' ]]; then + DOCKER_REPOSITORY=${DOCKER_REPOSITORY}-dev + fi + echo "::set-output name=DOCKER_REPOSITORY::${DOCKER_REPOSITORY}" + echo ${DOCKER_REPOSITORY} + # - name: Verifiy + # run : | + # echo ${{ steps.get-docker-repository.outputs.DOCKER_REPOSITORY }} - name: Checkout uses: actions/checkout@v2 @@ -73,8 +101,8 @@ jobs: cache-to: type=local,dest=/tmp/.buildx-cache-new push: true tags: | - nocodb/nocodb:${{ github.event.inputs.tag || inputs.tag }} - nocodb/nocodb:latest + nocodb/${{ steps.get-docker-repository.outputs.DOCKER_REPOSITORY }}:${{ github.event.inputs.tag || inputs.tag }} + nocodb/${{ steps.get-docker-repository.outputs.DOCKER_REPOSITORY }}:latest # Temp fix # https://github.com/docker/build-push-action/issues/252 diff --git a/.github/workflows/release-nightly-dev.yml b/.github/workflows/release-nightly-dev.yml new file mode 100644 index 0000000000..71450bc3d9 --- /dev/null +++ b/.github/workflows/release-nightly-dev.yml @@ -0,0 +1,59 @@ +name: 'NocoDB Nightly Dev Release' + +on: + # Triggered manually + workflow_dispatch: + inputs: + targetEnv: + description: "Target Environment" + required: true + type: choice + options: + - DEV + # - PROD + schedule: + # at the end of every day + - cron: '0 0 * * *' + +jobs: + # enrich tag for nightly auto release + set-tag: + runs-on: 'ubuntu-latest' + steps: + - name: set-tag + id: tag-step + run: | + # Get current date + CURRENT_DATE=$(date +"%Y%m%d") + CURRENT_TIME=$(date +"%H%M") + TAG_NAME=${CURRENT_DATE} + # Set the tag + if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then + TAG_NAME=${TAG_NAME}-${CURRENT_TIME} + fi + echo "::set-output name=NIGHTLY_BUILD_TAG::${TAG_NAME}" + # Verify the tag + - name: verify-tag + run: echo ${{ steps.tag-step.outputs.NIGHTLY_BUILD_TAG }} + outputs: + nightly_build_tag: ${{ steps.tag-step.outputs.NIGHTLY_BUILD_TAG }} + # Build frontend and backend and publish to npm + release-npm: + needs: set-tag + uses: ./.github/workflows/release-npm.yml + with: + tag: ${{ needs.set-tag.outputs.nightly_build_tag }} + targetEnv: ${{ github.event.inputs.targetEnv || 'DEV' }} + secrets: + NPM_TOKEN: "${{ secrets.NPM_TOKEN }}" + + # Build docker image and push to docker hub + release-docker: + needs: [set-tag, release-npm] + uses: ./.github/workflows/release-docker.yml + with: + tag: ${{ needs.set-tag.outputs.nightly_build_tag }} + targetEnv: ${{ github.event.inputs.targetEnv || 'DEV' }} + secrets: + DOCKERHUB_USERNAME: "${{ secrets.DOCKERHUB_USERNAME }}" + DOCKERHUB_TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}" diff --git a/.github/workflows/release-nocodb.yml b/.github/workflows/release-nocodb.yml index ff470dce3f..fa25dc65bb 100644 --- a/.github/workflows/release-nocodb.yml +++ b/.github/workflows/release-nocodb.yml @@ -30,6 +30,9 @@ jobs: uses: ./.github/workflows/release-npm.yml with: tag: ${{ github.event.inputs.tag }} + targetEnv: ${{ github.event.inputs.targetEnv || 'PROD' }} + secrets: + NPM_TOKEN: "${{ secrets.NPM_TOKEN }}" # Draft Release Note release-draft-note: @@ -45,6 +48,10 @@ jobs: uses: ./.github/workflows/release-docker.yml with: tag: ${{ github.event.inputs.tag }} + targetEnv: ${{ github.event.inputs.targetEnv || 'PROD' }} + secrets: + DOCKERHUB_USERNAME: "${{ secrets.DOCKERHUB_USERNAME }}" + DOCKERHUB_TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}" # Sync changes to develop sync-to-develop: diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml index 67d4436fbb..d9bf55fc2c 100644 --- a/.github/workflows/release-npm.yml +++ b/.github/workflows/release-npm.yml @@ -7,13 +7,29 @@ on: tag: description: "Tag" required: true - # Triggered by release-nocodb.yml + targetEnv: + description: "Target Environment" + required: true + type: choice + options: + - DEV + - PROD + # Triggered by release-nocodb.yml / release-nightly-dev.yml workflow_call: inputs: tag: description: "Tag" required: true type: string + targetEnv: + description: "Target Environment" + required: true + type: string + secrets: + NPM_TOKEN: + required: true +# GITHUB_TOKEN: +# required: true jobs: release: runs-on: ubuntu-latest @@ -32,21 +48,22 @@ jobs: - run: | cd packages/nc-gui npm install - npm run build:copy:jsdeliver + targetEnv=${{ github.event.inputs.targetEnv || inputs.targetEnv }} targetVersion=${{ github.event.inputs.tag || inputs.tag }} npm run build:copy:jsdeliver cd ../.. npm install - VERSION=${{ github.event.inputs.tag || inputs.tag }} node scripts/upgradeNcGui.js node scripts/upgradeNcGui.js && cd packages/nocodb && npm run obfuscate:build:publish + targetEnv=${{ github.event.inputs.targetEnv || inputs.targetEnv }} targetVersion=${{ github.event.inputs.tag || inputs.tag }} node scripts/upgradeNcGui.js && cd packages/nocodb && npm run obfuscate:build:publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Create Pull Request + if: ${{ github.event.inputs.targetEnv == 'PRD' || inputs.targetEnv == 'PRD' }} id: cpr uses: peter-evans/create-pull-request@v3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: -# commit-message: Update report -# committer: GitHub -# author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + # commit-message: Update report + # committer: GitHub + # author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> signoff: true branch: 'release/${{ github.event.inputs.tag || inputs.tag }}' delete-branch: true @@ -54,11 +71,12 @@ jobs: labels: | Bot: Automated PR - name: Check outputs + if: ${{ github.event.inputs.targetEnv == 'PROD' || inputs.targetEnv == 'PROD' }} run: | echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" - name: automerge uses: "pascalgn/automerge-action@v0.14.3" env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - PULL_REQUEST: "${{ steps.cpr.outputs.pull-request-number }}" + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + PULL_REQUEST: "${{ steps.cpr.outputs.pull-request-number }}" diff --git a/packages/nc-gui/nuxt.config.js b/packages/nc-gui/nuxt.config.js index d997871cb6..818ef22fec 100644 --- a/packages/nc-gui/nuxt.config.js +++ b/packages/nc-gui/nuxt.config.js @@ -175,7 +175,14 @@ export default { // // if (v === '99') throw new Error('Package version reached 99') // return `.${++v}` // }); - packageJson.version = version + if (process.env.targetEnv === 'DEV') { + // nightly build + // e.g. 0.84.2-20220220-1250 + packageJson.version = `${packageJson.version}-${process.env.targetVersion}` + packageJson.name += '-dev' + } else { + packageJson.version = version + } fs.writeFileSync('../nc-lib-gui/package.json', JSON.stringify(packageJson, 0, 2)) // config.output.publicPath = `https://cdn.jsdelivr.net/npm/nc-lib-gui@${version}/lib/dist/`; diff --git a/packages/nc-gui/package.json b/packages/nc-gui/package.json index 8a7db9a0b9..04d1262d95 100644 --- a/packages/nc-gui/package.json +++ b/packages/nc-gui/package.json @@ -8,7 +8,7 @@ "start": "EE=true nuxt start", "generate": "nuxt generate", "build:copy": "EE=true npm run build; rm -rf ../nc-lib-gui/lib/dist/; rsync -rvzh ./dist/ ../nc-lib-gui/lib/dist/", - "build:copy:jsdeliver": "npm run build; rm -rf ../nc-lib-gui/lib/dist/; rsync -rvzh ./dist/ ../nc-lib-gui/lib/dist/ ; npm publish ../nc-lib-gui" + "build:copy:jsdeliver": "npm run build; rm -rf ../nc-lib-gui/lib/dist/; rsync -rvzh ./dist/ ../nc-lib-gui/lib/dist/ ; npm publish ../nc-lib-gui" }, "dependencies": { "@mdi/font": "^5.9.55", diff --git a/scripts/upgradeNcGui.js b/scripts/upgradeNcGui.js index 8b31837155..34d1495893 100644 --- a/scripts/upgradeNcGui.js +++ b/scripts/upgradeNcGui.js @@ -6,10 +6,42 @@ const execSync = require('child_process').execSync; // extract latest version from package.json const ncLibPackage = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'packages', 'nc-lib-gui', 'package.json'))) -// upgrade nc-lib-gui version in nocodb -execSync(`cd packages/nocodb && npm install --save --save-exact nc-lib-gui@${ncLibPackage.version}`, {}); -const nocodbPackageFilePath = path.join(__dirname, '..', 'packages', 'nocodb', 'package.json') -const nocoLibPackage = JSON.parse(fs.readFileSync(nocodbPackageFilePath)) -nocoLibPackage.version = process.env.VERSION; -fs.writeFileSync(nocodbPackageFilePath, JSON.stringify(nocoLibPackage, null, 2)); +const replacePackageName = (filePath) => { + return new Promise((resolve, reject) => { + return fs.readFile(filePath, 'utf8', function (err, data) { + if (err) return reject(err) + var result = data.replace(/nc-lib-gui/g, ncLibPackage.name); + return fs.writeFile(filePath, result, 'utf8', function (err) { + if (err) return reject(err) + return resolve() + }); + }); + }) +} + +const bumbVersionAndSave = () => { + // upgrade nc-lib-gui version in nocodb + execSync(`cd packages/nocodb && npm install --save --save-exact ${ncLibPackage.name}@${ncLibPackage.version}`, {}); + const nocodbPackageFilePath = path.join(__dirname, '..', 'packages', 'nocodb', 'package.json') + const nocoLibPackage = JSON.parse(fs.readFileSync(nocodbPackageFilePath)) + nocoLibPackage.name = `${nocoLibPackage.name}-dev` + nocoLibPackage.version = ncLibPackage.version + fs.writeFileSync(nocodbPackageFilePath, JSON.stringify(nocoLibPackage, null, 2)); +} + +if (process.env.targetEnv === 'DEV') { + // replace nc-lib-gui by nc-lib-gui-dev if it is nightly build + const filePaths = [ + path.join(__dirname, '..', 'packages', 'nocodb', 'Dockerfile'), + path.join(__dirname, '..', 'packages', 'nocodb', 'litestream', 'Dockerfile'), + path.join(__dirname, '..', 'packages', 'nocodb', 'package.json'), + path.join(__dirname, '..', 'packages', 'nocodb', 'README.md'), + path.join(__dirname, '..', 'packages', 'nocodb', 'src', 'lib', 'noco', 'Noco.ts'), + ] + Promise.all(filePaths.map(filePath => { return replacePackageName(filePath) })).then(() => { + bumbVersionAndSave(); + }) +} else { + bumbVersionAndSave(); +} \ No newline at end of file From c9f47ec01c654be0971750569aacb30996a631cd Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 19 Feb 2022 16:37:20 +0800 Subject: [PATCH 2/2] fix: use GITHUB_TOKEN Signed-off-by: Wing-Kam Wong --- .github/workflows/release-draft.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-draft.yml b/.github/workflows/release-draft.yml index b2c1916c45..16a79de9c8 100644 --- a/.github/workflows/release-draft.yml +++ b/.github/workflows/release-draft.yml @@ -29,7 +29,7 @@ jobs: - name: Create tag uses: actions/github-script@v3 with: - github-token: ${{ secrets.GH_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} script: | github.git.createRef({ owner: context.repo.owner, @@ -45,4 +45,4 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 14 - - run: "npx github-release-notes@0.17.2 release --token ${{ secrets.GH_TOKEN }} --draft --tags ${{ github.event.inputs.tag || inputs.tag }}..${{ github.event.inputs.prev_tag || inputs.prev_tag }}" + - run: "npx github-release-notes@0.17.2 release --token ${{ secrets.GITHUB_TOKEN }} --draft --tags ${{ github.event.inputs.tag || inputs.tag }}..${{ github.event.inputs.prev_tag || inputs.prev_tag }}"