chore: update ci

This commit is contained in:
chenos 2022-12-13 10:18:36 +08:00
parent 49a4899959
commit b74300cb16
7 changed files with 20 additions and 307 deletions

View File

@ -16,6 +16,7 @@ on:
jobs: jobs:
push-acr: push-acr:
if: github.event.pull_request.head.repo.fork !== true
runs-on: ubuntu-latest runs-on: ubuntu-latest
services: services:
verdaccio: verdaccio:

View File

@ -1,69 +0,0 @@
name: Auto Deploy Main
# deploy_host
# deploy_host_username
# deploy_host_password
# https://docs.github.com/cn/actions/using-workflows/events-that-trigger-workflows#workflow_run
env:
nocobase_main_deploy_path: /home/ecs-user/nocobase/main
nocobase_develop_deploy_path: /home/ecs-user/nocobase/develop
on:
workflow_run:
workflows: [ "Aliyun Container Registry" ]
types:
- "completed"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 'Download image tag artifact'
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "image_tag"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/image_tag.zip`, Buffer.from(download.data));
- name: 'Unzip image tag artifact'
run: unzip image_tag.zip
- name: 'set image_tag to env'
run: |
image_tag=`cat ./image_tag`
echo "image_tag=$image_tag" >> $GITHUB_ENV
- name: ssh deploy main
if: env.image_tag == 'nocobase/nocobase:main'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.deploy_host }}
username: ${{ secrets.deploy_host_username }}
password: ${{ secrets.deploy_host_password }}
script: |
cd ${{ env.nocobase_main_deploy_path }}
sudo docker compose pull && sudo docker compose up -d
- name: ssh deploy develop
if: env.image_tag == 'nocobase/nocobase:develop'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.deploy_host }}
username: ${{ secrets.deploy_host_username }}
password: ${{ secrets.deploy_host_password }}
script: |
cd ${{ env.nocobase_develop_deploy_path }}
sudo docker compose pull && sudo docker compose up -d

View File

@ -1,57 +0,0 @@
name: Auto Deploy Pr
# deploy_host
# deploy_host_username
# deploy_host_password
# https://docs.github.com/cn/actions/using-workflows/events-that-trigger-workflows#workflow_run
env:
nocobase_deploy_sh_dir: /home/ecs-user/nocobase/auto-deploy-pr/
on:
workflow_run:
workflows: [ "Aliyun Container Registry" ]
types:
- "completed"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: 'Download pr number artifact'
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
- name: 'Unzip pr number artifact'
run: unzip pr_number.zip
- name: 'set pr_number to env'
run: |
pr_number=`cat ./pr_number`
echo "pr_number=$pr_number" >> $GITHUB_ENV
- name: ssh deploy
if: ${{ env.pr_number }}
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.deploy_host }}
username: ${{ secrets.deploy_host_username }}
password: ${{ secrets.deploy_host_password }}
script: |
cd ${{ env.nocobase_deploy_sh_dir }}
./nocobase-deploy.sh up ${{ env.pr_number }}

View File

@ -1,33 +1,32 @@
name: Auto down deploy name: Auto down deploy
# deploy_host
# deploy_host_username
# deploy_host_password
# https://docs.github.com/cn/actions/using-workflows/events-that-trigger-workflows#workflow_run
env:
nocobase_deploy_sh_dir: /home/ecs-user/nocobase/auto-deploy-pr/
on: on:
pull_request: pull_request:
types: types:
- closed - closed
branches: branches:
- '**' - '**'
paths:
- 'packages/**'
jobs: jobs:
down_deploy: down:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: ssh down deploy - name: Docker meta
if: github.event.pull_request.merged == true id: meta
uses: appleboy/ssh-action@master uses: docker/metadata-action@v4
env:
pr_number: ${{ github.event.number }}
with: with:
host: ${{ secrets.deploy_host }} images: |
username: ${{ secrets.deploy_host_username }} nocobase/nocobase
password: ${{ secrets.deploy_host_password }} tags: |
script: | type=ref,event=branch
cd ${{ env.nocobase_deploy_sh_dir }} type=ref,event=pr
./nocobase-deploy.sh down ${{ env.pr_number }} type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Down ${{ steps.meta.outputs.tags }}
env:
IMAGE_TAG: ${{ steps.meta.outputs.tags }}
run: |
echo $IMAGE_TAG
export APP_NAME=$(echo $IMAGE_TAG | cut -d ":" -f 2)
echo $APP_NAME
curl --location --request DELETE "${{secrets.NOCOBASE_DEPLOY_HOST}}$APP_NAME"

View File

@ -1,28 +0,0 @@
name: Auto send feishu bot msg
on:
workflow_run:
workflows: [ "Aliyun Container Registry" ]
types:
- "completed"
jobs:
send_feishu_bot_msg:
runs-on: ubuntu-latest
steps:
- name: pr deploy text message
if: github.event_name == 'pull_request'
uses: foxundermoon/feishu-action@v2
with:
url: ${{ secrets.PR_FEISHU_BOT_WEBHOOK_URL }}
msg_type: text
content: |
text: |
地址:${{ github.event.pull_request.html_url }}
标题:${{ github.event.pull_request.title }}
分支:${{ github.event.pull_request.head.ref }}
触发者:${{ github.triggering_actor }}
----------------------------------------------
正在自动部署环境-稍后访问地址http://${{ secrets.deploy_host }}:1${{ github.event.number }}
-----------------------------------------------
请及时更新任务系统的任务状态https://tasks.nocobase.com/

View File

@ -1,113 +0,0 @@
name: manual_down_deploy_pr
# deploy_host
# deploy_host_username
# deploy_host_password
env:
nocobase_deploy_sh_dir: /home/ecs-user/nocobase/auto-deploy-pr/
on:
workflow_dispatch:
inputs:
pr_number:
description: 'fork pr number is '
required: true
jobs:
up_deploy:
runs-on: ubuntu-latest
services:
verdaccio:
image: verdaccio/verdaccio
ports:
- 4873:4873
steps:
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@v2
with:
# Optional, GitHub token, a Personal Access Token with `public_repo` scope if needed
# Required, if the artifact is from a different repo
# Required, if the repo is private a Personal Access Token with `repo` scope is needed
github_token: ${{secrets.GITHUB_TOKEN}}
# Optional, workflow file name or ID
# If not specified, will be inferred from run_id (if run_id is specified), or will be the current workflow
workflow: upload_fork_pr_files.yml
# Optional, the status or conclusion of a completed workflow to search for
# Can be one of a workflow conclusion:
# "failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required"
# Or a workflow status:
# "completed", "in_progress", "queued"
# Use the empty string ("") to ignore status or conclusion in the search
workflow_conclusion: success
# Optional, will get head commit SHA
pr: ${{ inputs.pr_number }}
# Optional, no need to specify if PR is
# commit: ${{github.event.pull_request.head.sha}}
# Optional, will use the specified branch. Defaults to all branches
# branch: master
# Optional, defaults to all types
# event: push
# Optional, will use specified workflow run
# run_id: 1122334455
# Optional, run number from the workflow
# run_number: 34
# Optional, uploaded artifact name,
# will download all artifacts if not specified
# and extract them into respective subdirectories
# https://github.com/actions/download-artifact#download-all-artifacts
name: pr_files
# Optional, a directory where to extract artifact(s), defaults to the current directory
# path: extract_here
# Optional, defaults to current repo
# repo: ${{ github.repository }}
# Optional, check the workflow run to whether it has an artifact
# then will get the last available artifact from the previous workflow
# default false, just try to download from the last one
# check_artifacts: false
# Optional, search for the last workflow run whose stored an artifact named as in `name` input
# default false
search_artifacts: false
# Optional, choose to skip unpacking the downloaded artifact(s)
# default false
skip_unpack: false
# Optional, choose how to exit the action if no artifact is found
# can be one of:
# "fail", "warn", "ignore"
# default fail
if_no_artifact_found: fail
- 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 Docker Hub
uses: docker/login-action@v2
with:
registry: ${{ secrets.ALI_DOCKER_REGISTRY }}
username: ${{ secrets.ALI_DOCKER_USERNAME }}
password: ${{ secrets.ALI_DOCKER_PASSWORD }}
- 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}
push: true
tags: ${{ secrets.ALI_DOCKER_REGISTRY }}/nocobase/nocobase:pr-${{ inputs.pr_number }}
- name: ssh deploy
uses: appleboy/ssh-action@master
env:
pr_number: ${{ inputs.pr_number }}
with:
host: ${{ secrets.deploy_host }}
username: ${{ secrets.deploy_host_username }}
password: ${{ secrets.deploy_host_password }}
script: |
cd ${{ env.nocobase_deploy_sh_dir }}
./nocobase-deploy.sh up ${{ env.pr_number }}

View File

@ -1,20 +0,0 @@
name: Upload fork pr files
on:
pull_request:
branches:
- '**'
paths:
- 'packages/**'
jobs:
upload-fork-pr-files:
if: github.event.pull_request.head.repo.fork == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/upload-artifact@v3
with:
name: pr_files
path: ./