|
| 1 | +name: Auto Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: CheckOut Code |
| 15 | + uses: actions/checkout@master |
| 16 | + with: |
| 17 | + ref: ${{ github.ref_name }} |
| 18 | + |
| 19 | + - name: Setup pnpm |
| 20 | + uses: pnpm/action-setup@v2 |
| 21 | + |
| 22 | + - name: Setup Node |
| 23 | + uses: actions/setup-node@v3 |
| 24 | + with: |
| 25 | + node-version: 20.10.0 |
| 26 | + registry-url: "https://registry.npmjs.org" |
| 27 | + |
| 28 | + - name: Get pnpm store directory |
| 29 | + id: pnpm-cache |
| 30 | + run: | |
| 31 | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 32 | +
|
| 33 | + - uses: actions/cache@v3 |
| 34 | + name: Setup pnpm cache |
| 35 | + with: |
| 36 | + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} |
| 37 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-pnpm-store- |
| 40 | + - name: Install dependencies |
| 41 | + run: pnpm i --no-frozen-lockfile |
| 42 | + - name: Build |
| 43 | + run: | |
| 44 | + pnpm build |
| 45 | + - name: Upload build artifact |
| 46 | + uses: actions/upload-artifact@v4 |
| 47 | + with: |
| 48 | + name: dist-artifact |
| 49 | + path: dist/ |
| 50 | + # Publish job |
| 51 | + publish: |
| 52 | + needs: build |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - name: Download build artifact |
| 56 | + uses: actions/download-artifact@v4 |
| 57 | + with: |
| 58 | + name: dist-artifact |
| 59 | + path: dist/ |
| 60 | + - name: Parse Publish tag |
| 61 | + id: parse_tag |
| 62 | + run: | |
| 63 | + tag_name="${GITHUB_REF#refs/tags/}" |
| 64 | + if [[ "$tag_name" == *alpha* ]]; then |
| 65 | + echo "dist_tag=alpha" >> "$GITHUB_OUTPUT" |
| 66 | + elif [[ "$tag_name" == *beta* ]]; then |
| 67 | + echo "dist_tag=beta" >> "$GITHUB_OUTPUT" |
| 68 | + elif [[ "$tag_name" == *rc* ]]; then |
| 69 | + echo "dist_tag=rc" >> "$GITHUB_OUTPUT" |
| 70 | + else |
| 71 | + echo "dist_tag=latest" >> "$GITHUB_OUTPUT" |
| 72 | + fi |
| 73 | + - name: Show version and tag |
| 74 | + run: | |
| 75 | + VERSION="$(node -p "require('./package.json').version")" |
| 76 | + echo "publish version: $VERSION" |
| 77 | + echo "publish tag: ${{ steps.parse_tag.outputs.dist_tag }}" |
| 78 | + - name: Publish @opentiny/fluent-editor |
| 79 | + run: | |
| 80 | + echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc |
| 81 | + npm publish --tag ${{ steps.parse_tag.outputs.dist_tag }} |
| 82 | + env: |
| 83 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 84 | + |
| 85 | + - name: Release |
| 86 | + if: ${{ steps.parse_tag.outputs.dist_tag == 'latest' }} |
| 87 | + uses: softprops/action-gh-release@v1 |
| 88 | + with: |
| 89 | + tag_name: ${{ github.ref_name }} |
| 90 | + generate_release_notes: true |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} |
0 commit comments