From d9a6c143058b39216cd239561e6d30b7b1d16092 Mon Sep 17 00:00:00 2001 From: chilingling Date: Tue, 7 Jan 2025 22:39:44 -0800 Subject: [PATCH 1/3] feat: add auto publish workflow --- .github/workflows/Release.yml | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/Release.yml diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml new file mode 100644 index 0000000000..cd0385ade4 --- /dev/null +++ b/.github/workflows/Release.yml @@ -0,0 +1,55 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + if: github.repository == '@opentiny/tiny-engine' + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + run_install: false + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: 'pnpm' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: pnpm install + + - name: Run Build + run: pnpm run build:plugin && pnpm run build:alpha > build-alpha.log 2>&1 + + - name: Parse Publish tag + id: parse_tag + run: | + tag_name="${GITHUB_REF#refs/tags/}" + if [["$tag_name" == *alpha*]]; then + echo "dist_tag=alpha" >> $GITHUB_OUTPUT + elif [["$tag_name" == *beta*]]; then + echo "dist_tag=beta" >> $GITHUB_OUTPUT + elif [["$tag_name" == *rc*]]; then + echo "dist_tag=rc" >> $GITHUB_OUTPUT + else + echo "dist_tag=latest" >> $GITHUB_OUTPUT + fi + + - name: Publish package to npm + run: pnpm lerna publish from-package --pre-dist-tag ${{steps.parse_tag.outputs.dist_tag}} --yes + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} From 41d3a4b2829468e8c98d10e8a2b9ecc0263b9dfa Mon Sep 17 00:00:00 2001 From: chilingling Date: Tue, 7 Jan 2025 23:21:50 -0800 Subject: [PATCH 2/3] fix: add verify steps --- .github/workflows/Release.yml | 36 +++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index cd0385ade4..9cc8a0e0e7 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -7,7 +7,7 @@ on: jobs: release: - if: github.repository == '@opentiny/tiny-engine' + if: github.repository == 'opentiny/tiny-engine' runs-on: ubuntu-latest permissions: contents: write @@ -33,23 +33,47 @@ jobs: run: pnpm install - name: Run Build - run: pnpm run build:plugin && pnpm run build:alpha > build-alpha.log 2>&1 + run: | + pnpm run build:plugin + pnpm run build:alpha > build-alpha.log 2>&1 + + - name: Upload build logs + uses: actions/upload-artifact@v4 + with: + name: build-alpha-log + path: build-alpha.log - name: Parse Publish tag id: parse_tag run: | tag_name="${GITHUB_REF#refs/tags/}" - if [["$tag_name" == *alpha*]]; then + if [[ "$tag_name" == *alpha* ]]; then echo "dist_tag=alpha" >> $GITHUB_OUTPUT - elif [["$tag_name" == *beta*]]; then + elif [[ "$tag_name" == *beta* ]]; then echo "dist_tag=beta" >> $GITHUB_OUTPUT - elif [["$tag_name" == *rc*]]; then + elif [[ "$tag_name" == *rc* ]]; then echo "dist_tag=rc" >> $GITHUB_OUTPUT else echo "dist_tag=latest" >> $GITHUB_OUTPUT fi + - name: Verify clean working directory + run: | + if [[ -n $(git status --porcelain) ]]; then + echo "Working directory is not clean" + exit 1 + fi + + - name: Verify package version match tag + run: | + tag_name="${GITHUB_REF#refs/tags/}" + package_version=$(pnpm lerna list --scope=@opentiny/tiny-engine --json | jq -r '.[0].version') + if [[ "$tag_name" != "v$package_version" ]]; then + echo "Tag name $tag_name does not match package version $package_version" + exit 1 + fi + - name: Publish package to npm - run: pnpm lerna publish from-package --pre-dist-tag ${{steps.parse_tag.outputs.dist_tag}} --yes + run: pnpm lerna publish from-package --dist-tag ${{steps.parse_tag.outputs.dist_tag}} --yes env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} From ec512c18ff23c34d170a98e1c600a2d881e57b5f Mon Sep 17 00:00:00 2001 From: chilingling Date: Tue, 7 Jan 2025 23:35:11 -0800 Subject: [PATCH 3/3] fix: shell syntax issue --- .github/workflows/Release.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 9cc8a0e0e7..2e64ad8fe2 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -33,9 +33,7 @@ jobs: run: pnpm install - name: Run Build - run: | - pnpm run build:plugin - pnpm run build:alpha > build-alpha.log 2>&1 + run: pnpm run build:plugin && pnpm run build:alpha > build-alpha.log 2>&1 - name: Upload build logs uses: actions/upload-artifact@v4 @@ -48,18 +46,18 @@ jobs: run: | tag_name="${GITHUB_REF#refs/tags/}" if [[ "$tag_name" == *alpha* ]]; then - echo "dist_tag=alpha" >> $GITHUB_OUTPUT + echo "dist_tag=alpha" >> "$GITHUB_OUTPUT" elif [[ "$tag_name" == *beta* ]]; then - echo "dist_tag=beta" >> $GITHUB_OUTPUT + echo "dist_tag=beta" >> "$GITHUB_OUTPUT" elif [[ "$tag_name" == *rc* ]]; then - echo "dist_tag=rc" >> $GITHUB_OUTPUT + echo "dist_tag=rc" >> "$GITHUB_OUTPUT" else - echo "dist_tag=latest" >> $GITHUB_OUTPUT + echo "dist_tag=latest" >> "$GITHUB_OUTPUT" fi - name: Verify clean working directory run: | - if [[ -n $(git status --porcelain) ]]; then + if [[ -n "$(git status --porcelain)" ]]; then echo "Working directory is not clean" exit 1 fi