|
6 | 6 | - v* |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - test-and-build: |
10 | | - runs-on: ubuntu-24.04 |
| 9 | + test: |
| 10 | + uses: ./.github/workflows/test.yml |
| 11 | + |
| 12 | + publish-npm-package: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + needs: test |
| 15 | + outputs: |
| 16 | + npm_tag: ${{ steps.npm_tag.outputs.value }} |
| 17 | + permissions: |
| 18 | + id-token: write |
| 19 | + contents: read |
| 20 | + packages: write |
11 | 21 | steps: |
12 | | - - name: Clone |
13 | | - uses: actions/checkout@v3 |
14 | | - |
15 | | - - uses: actions/setup-node@v4 |
| 22 | + - uses: actions/checkout@v6 |
| 23 | + - name: Get tag |
| 24 | + id: npm_tag |
| 25 | + run: | |
| 26 | + VERSION="${GITHUB_REF_NAME#v}" |
| 27 | + # e.g.: x.y.z -> latest, x.y.z-rc.1 -> rc |
| 28 | + TAG=$([[ "$VERSION" == *-* ]] && echo "${VERSION#*-}" | cut -d. -f1 || echo latest) |
| 29 | + echo "value=$TAG" >> $GITHUB_OUTPUT |
| 30 | + - uses: actions/setup-node@v6 |
16 | 31 | with: |
17 | | - cache: "npm" |
18 | | - node-version-file: '.nvmrc' |
19 | | - |
| 32 | + cache: npm |
| 33 | + node-version-file: .nvmrc |
| 34 | + registry-url: https://registry.npmjs.org |
| 35 | + - name: Set version in package.json |
| 36 | + run: npm --no-git-tag-version version "${GITHUB_REF_NAME#v}" |
20 | 37 | - name: Install |
21 | 38 | run: npm ci |
22 | | - |
23 | 39 | - name: Build |
24 | 40 | run: npm run build |
25 | | - |
26 | | - - name: Unit Test |
27 | | - run: npm run test |
28 | | - |
29 | | - - name: Upload dist |
30 | | - uses: actions/upload-artifact@v4 |
31 | | - with: |
32 | | - name: dist |
33 | | - path: | |
34 | | - dist/* |
35 | | -
|
36 | | - publish-github-release: |
37 | | - name: Publish to GitHub |
38 | | - runs-on: ubuntu-24.04 |
39 | | - needs: test-and-build |
40 | | - steps: |
41 | | - - name: Get Token |
42 | | - id: get_workflow_token |
43 | | - uses: peter-murray/workflow-application-token-action@v2 |
44 | | - with: |
45 | | - application_id: ${{ secrets.CC_OSS_BOT_ID }} |
46 | | - application_private_key: ${{ secrets.CC_OSS_BOT_PEM }} |
47 | | - |
48 | | - - name: Swap to main |
49 | | - uses: actions/checkout@v3 |
50 | | - with: |
51 | | - ref: main |
52 | | - fetch-depth: 0 # Full fetch |
53 | | - token: ${{ steps.get_workflow_token.outputs.token }} |
54 | | - |
55 | | - - name: Get Version |
56 | | - run: | |
57 | | - GIT_VERSION=$(node ./.backstage/get_tagged_version.cjs) |
58 | | - echo GIT_VERSION="$GIT_VERSION" >> $GITHUB_ENV |
59 | | - - name: Get Release Tag |
60 | | - run: | |
61 | | - NPM_TAG=$(node ./.backstage/get_npm_tag.cjs) |
62 | | - echo NPM_TAG="$NPM_TAG" >> $GITHUB_ENV |
63 | | -
|
64 | | - - name: Download dist |
65 | | - uses: actions/download-artifact@v4 |
| 41 | + - name: Publish package on npm |
| 42 | + run: npm publish --tag ${{ steps.npm_tag.outputs.value }} |
| 43 | + - uses: actions/setup-node@v6 |
66 | 44 | with: |
67 | | - name: dist |
68 | | - path: dist |
69 | | - |
70 | | - - name: List files |
71 | | - run: ls -R dist |
72 | | - |
73 | | - - name: Stable Release |
74 | | - uses: softprops/action-gh-release@v2.2.2 |
75 | | - if: startsWith(github.ref, 'refs/tags/') && env.NPM_TAG == 'latest' |
76 | | - with: |
77 | | - files: | |
78 | | - dist/* |
| 45 | + registry-url: https://npm.pkg.github.com |
| 46 | + - name: Publish package on GitHub |
| 47 | + run: npm publish --tag ${{ steps.npm_tag.outputs.value }} |
79 | 48 | env: |
80 | | - GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} |
| 49 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
81 | 50 |
|
82 | | - - name: Prerelease |
83 | | - uses: softprops/action-gh-release@v2.2.2 |
84 | | - if: startsWith(github.ref, 'refs/tags/') && env.NPM_TAG != 'latest' |
85 | | - with: |
86 | | - prerelease: true |
87 | | - files: | |
88 | | - dist/* |
89 | | - env: |
90 | | - GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} |
91 | | - |
92 | | - publish-npm-release: |
93 | | - runs-on: ubuntu-24.04 |
94 | | - needs: publish-github-release |
| 51 | + create-github-release: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: publish-npm-package |
| 54 | + permissions: |
| 55 | + contents: write |
95 | 56 | steps: |
96 | | - - name: Clone |
97 | | - uses: actions/checkout@v3 |
98 | | - |
99 | | - - uses: actions/setup-node@v4 |
100 | | - with: |
101 | | - cache: "npm" |
102 | | - node-version-file: '.nvmrc' |
103 | | - |
104 | | - - name: Get Version |
| 57 | + - name: Create release |
105 | 58 | run: | |
106 | | - GIT_VERSION=$(node ./.backstage/get_tagged_version.cjs) |
107 | | - echo GIT_VERSION="$GIT_VERSION" >> $GITHUB_ENV |
108 | | - - name: Get Release Tag |
109 | | - run: | |
110 | | - NPM_TAG=$(node ./.backstage/get_npm_tag.cjs) |
111 | | - echo NPM_TAG="$NPM_TAG" >> $GITHUB_ENV |
112 | | -
|
113 | | - - name: Prepare package |
114 | | - run: | |
115 | | - npm --no-git-tag-version version $GIT_VERSION |
116 | | -
|
117 | | - - name: Install |
118 | | - run: npm ci |
119 | | - |
120 | | - - name: Build |
121 | | - run: npm run build |
122 | | - |
123 | | - - name: Publish internal |
124 | | - uses: JS-DevTools/npm-publish@v3 |
125 | | - with: |
126 | | - tag: ${{ env.NPM_TAG }} |
127 | | - token: ${{ secrets.GITHUB_TOKEN }} |
128 | | - registry: "https://npm.pkg.github.com" |
129 | | - |
130 | | - - name: Publish external |
131 | | - uses: JS-DevTools/npm-publish@v3 |
132 | | - with: |
133 | | - tag: ${{ env.NPM_TAG }} |
134 | | - token: ${{ secrets.NPM_TOKEN }} |
135 | | - access: public |
| 59 | + if [ "${{ needs.publish-npm-package.outputs.npm_tag }}" = "latest" ]; then |
| 60 | + gh release create ${{ github.ref_name }} --generate-notes --repo ${{ github.repository }} |
| 61 | + else |
| 62 | + gh release create ${{ github.ref_name }} --generate-notes --prerelease --repo ${{ github.repository }} |
| 63 | + fi |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments