From 04e7a9fc14ff88914e65c8cf155b6b86558de083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=8D=8E=E6=A1=A5?= Date: Wed, 20 Dec 2023 17:26:22 +0800 Subject: [PATCH] ci: use setup version action to init version --- .github/actions/setup-version/action.yml | 20 ++++++++++++++++++ .github/workflows/deploy.yml | 26 ++++++++++++++++-------- 2 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 .github/actions/setup-version/action.yml diff --git a/.github/actions/setup-version/action.yml b/.github/actions/setup-version/action.yml new file mode 100644 index 0000000000..4703be8359 --- /dev/null +++ b/.github/actions/setup-version/action.yml @@ -0,0 +1,20 @@ +name: Setup Version +description: 'Setup Version' +runs: + using: 'composite' + steps: + - name: 'Write Version' + id: version + shell: bash + run: | + if [ "${{ github.ref_type }}" == "tag" ]; then + APP_VERSION=${{ github.ref_name }} + else + PACKAGE_VERSION=$(node -p "require('./package.json').version") + TIME_VERSION=$(date +%Y%m%d%H%M) + GIT_SHORT_HASH=$(git rev-parse --short HEAD) + APP_VERSION=$PACKAGE_VERSION-nightly-$TIME_VERSION-$GIT_SHORT_HASH + fi + echo $APP_VERSION + echo "APP_VERSION=$APP_VERSION" >> "$GITHUB_OUTPUT" + ./scripts/set-version.sh $APP_VERSION diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d0ec8394af..7749f50975 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,10 +4,14 @@ on: workflow_dispatch: inputs: flavor: - description: 'Build type (canary, beta, or stable or internal)' - type: string + description: 'Select what enverionment to deploy to' + type: choice default: canary - + options: + - canary + - beta + - stable + - internal env: APP_NAME: affine NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} @@ -18,6 +22,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Setup Version + uses: ./.github/actions/setup-version - name: Setup Node.js uses: ./.github/actions/setup-node with: @@ -36,6 +42,8 @@ jobs: environment: ${{ github.event.inputs.flavor }} steps: - uses: actions/checkout@v4 + - name: Setup Version + uses: ./.github/actions/setup-version - name: Setup Node.js uses: ./.github/actions/setup-node - name: Build Plugins @@ -67,6 +75,8 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Setup Version + uses: ./.github/actions/setup-version - name: Setup Node.js uses: ./.github/actions/setup-node - name: Build Rust @@ -88,6 +98,8 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Setup Version + uses: ./.github/actions/setup-version - name: Setup Node.js uses: ./.github/actions/setup-node - name: Build Rust @@ -207,12 +219,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: setup deploy version - id: version - run: | - export APP_VERSION=`node -e "console.log(require('./package.json').version)"` - echo $APP_VERSION - echo "APP_VERSION=$APP_VERSION" >> "$GITHUB_OUTPUT" + - name: Setup Version + uses: ./.github/actions/setup-version - name: Deploy to ${{ github.event.inputs.flavor }} uses: ./.github/actions/deploy with: