Browse Source

refactor: github actions & nightly-build

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>
pull/1308/head
Wing-Kam Wong 3 years ago
parent
commit
68061a5d29
  1. 34
      .github/workflows/release-docker.yml
  2. 59
      .github/workflows/release-nightly-dev.yml
  3. 7
      .github/workflows/release-nocodb.yml
  4. 30
      .github/workflows/release-npm.yml
  5. 7
      packages/nc-gui/nuxt.config.js
  6. 44
      scripts/upgradeNcGui.js

34
.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

59
.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 }}"

7
.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:

30
.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 <noreply@github.com>
# author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
# commit-message: Update report
# committer: GitHub <noreply@github.com>
# author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: true
branch: 'release/${{ github.event.inputs.tag || inputs.tag }}'
delete-branch: true
@ -54,6 +71,7 @@ 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 }}"

7
packages/nc-gui/nuxt.config.js

@ -175,7 +175,14 @@ export default {
// // if (v === '99') throw new Error('Package version reached 99')
// return `.${++v}`
// });
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/`;

44
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();
}
Loading…
Cancel
Save