Browse Source

Merge pull request #1308 from nocodb/refactor/nightly-build

refactor: github actions & nightly-build
pull/1309/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
0d442676ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      .github/workflows/release-docker.yml
  2. 4
      .github/workflows/release-draft.yml
  3. 59
      .github/workflows/release-nightly-dev.yml
  4. 7
      .github/workflows/release-nocodb.yml
  5. 34
      .github/workflows/release-npm.yml
  6. 9
      packages/nc-gui/nuxt.config.js
  7. 2
      packages/nc-gui/package.json
  8. 44
      scripts/upgradeNcGui.js

34
.github/workflows/release-docker.yml

@ -7,13 +7,29 @@ on:
tag: tag:
description: "Docker image tag" description: "Docker image tag"
required: true 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: workflow_call:
inputs: inputs:
tag: tag:
description: "Docker image tag" description: "Docker image tag"
required: true required: true
type: string type: string
targetEnv:
description: "Target Environment"
required: true
type: string
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
jobs: jobs:
buildx: buildx:
@ -24,6 +40,18 @@ jobs:
matrix: matrix:
node-version: [12] node-version: [12]
steps: 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 - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -73,8 +101,8 @@ jobs:
cache-to: type=local,dest=/tmp/.buildx-cache-new cache-to: type=local,dest=/tmp/.buildx-cache-new
push: true push: true
tags: | tags: |
nocodb/nocodb:${{ github.event.inputs.tag || inputs.tag }} nocodb/${{ steps.get-docker-repository.outputs.DOCKER_REPOSITORY }}:${{ github.event.inputs.tag || inputs.tag }}
nocodb/nocodb:latest nocodb/${{ steps.get-docker-repository.outputs.DOCKER_REPOSITORY }}:latest
# Temp fix # Temp fix
# https://github.com/docker/build-push-action/issues/252 # https://github.com/docker/build-push-action/issues/252

4
.github/workflows/release-draft.yml

@ -29,7 +29,7 @@ jobs:
- name: Create tag - name: Create tag
uses: actions/github-script@v3 uses: actions/github-script@v3
with: with:
github-token: ${{ secrets.GH_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
script: | script: |
github.git.createRef({ github.git.createRef({
owner: context.repo.owner, owner: context.repo.owner,
@ -45,4 +45,4 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 14 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 }}"

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 uses: ./.github/workflows/release-npm.yml
with: with:
tag: ${{ github.event.inputs.tag }} tag: ${{ github.event.inputs.tag }}
targetEnv: ${{ github.event.inputs.targetEnv || 'PROD' }}
secrets:
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
# Draft Release Note # Draft Release Note
release-draft-note: release-draft-note:
@ -45,6 +48,10 @@ jobs:
uses: ./.github/workflows/release-docker.yml uses: ./.github/workflows/release-docker.yml
with: with:
tag: ${{ github.event.inputs.tag }} 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 changes to develop
sync-to-develop: sync-to-develop:

34
.github/workflows/release-npm.yml

@ -7,13 +7,29 @@ on:
tag: tag:
description: "Tag" description: "Tag"
required: true 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: workflow_call:
inputs: inputs:
tag: tag:
description: "Tag" description: "Tag"
required: true required: true
type: string type: string
targetEnv:
description: "Target Environment"
required: true
type: string
secrets:
NPM_TOKEN:
required: true
# GITHUB_TOKEN:
# required: true
jobs: jobs:
release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -32,21 +48,22 @@ jobs:
- run: | - run: |
cd packages/nc-gui cd packages/nc-gui
npm install 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 ../.. cd ../..
npm install 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: env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Pull Request - name: Create Pull Request
if: ${{ github.event.inputs.targetEnv == 'PRD' || inputs.targetEnv == 'PRD' }}
id: cpr id: cpr
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v3
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
# commit-message: Update report # commit-message: Update report
# committer: GitHub <noreply@github.com> # committer: GitHub <noreply@github.com>
# author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> # author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: true signoff: true
branch: 'release/${{ github.event.inputs.tag || inputs.tag }}' branch: 'release/${{ github.event.inputs.tag || inputs.tag }}'
delete-branch: true delete-branch: true
@ -54,11 +71,12 @@ jobs:
labels: | labels: |
Bot: Automated PR Bot: Automated PR
- name: Check outputs - name: Check outputs
if: ${{ github.event.inputs.targetEnv == 'PROD' || inputs.targetEnv == 'PROD' }}
run: | run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
- name: automerge - name: automerge
uses: "pascalgn/automerge-action@v0.14.3" uses: "pascalgn/automerge-action@v0.14.3"
env: env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
PULL_REQUEST: "${{ steps.cpr.outputs.pull-request-number }}" PULL_REQUEST: "${{ steps.cpr.outputs.pull-request-number }}"

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

@ -175,7 +175,14 @@ export default {
// // if (v === '99') throw new Error('Package version reached 99') // // if (v === '99') throw new Error('Package version reached 99')
// return `.${++v}` // 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)) 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/`; // config.output.publicPath = `https://cdn.jsdelivr.net/npm/nc-lib-gui@${version}/lib/dist/`;

2
packages/nc-gui/package.json

@ -8,7 +8,7 @@
"start": "EE=true nuxt start", "start": "EE=true nuxt start",
"generate": "nuxt generate", "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": "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": { "dependencies": {
"@mdi/font": "^5.9.55", "@mdi/font": "^5.9.55",

44
scripts/upgradeNcGui.js

@ -6,10 +6,42 @@ const execSync = require('child_process').execSync;
// extract latest version from package.json // extract latest version from package.json
const ncLibPackage = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'packages', 'nc-lib-gui', '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 replacePackageName = (filePath) => {
const nocoLibPackage = JSON.parse(fs.readFileSync(nocodbPackageFilePath)) return new Promise((resolve, reject) => {
nocoLibPackage.version = process.env.VERSION; return fs.readFile(filePath, 'utf8', function (err, data) {
fs.writeFileSync(nocodbPackageFilePath, JSON.stringify(nocoLibPackage, null, 2)); 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