|
1 | | -name: Publish @bcgov/design-tokens to npm |
| 1 | +name: Publish @bcgov/design-tokens to npm and GitHub Packages |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
|
10 | 10 | types: [published] |
11 | 11 |
|
12 | 12 | permissions: |
13 | | - id-token: write # Required for OIDC |
14 | 13 | contents: read |
15 | 14 |
|
16 | 15 | jobs: |
17 | | - publish-design-tokens-next: |
18 | | - name: Publish @bcgov/design-tokens@next |
19 | | - # Publish a `next` version on PR merge to main branch. |
| 16 | + publish-design-tokens-npm-next: |
| 17 | + name: Publish @bcgov/design-tokens@next to npm |
| 18 | + # Publish a `next` version to npm on PR merge to main branch. |
20 | 19 | if: ${{ github.event.pull_request.merged == true && github.repository == 'bcgov/design-system' }} |
| 20 | + permissions: |
| 21 | + id-token: write # Required for OIDC |
21 | 22 | runs-on: ubuntu-latest |
22 | 23 |
|
23 | 24 | steps: |
@@ -73,12 +74,74 @@ jobs: |
73 | 74 | run: npm publish --tag next |
74 | 75 | working-directory: ./packages/design-tokens/dist |
75 | 76 |
|
76 | | - publish-design-tokens-latest: |
77 | | - name: Publish @bcgov/design-tokens@latest |
78 | | - # Publish a `latest` version only when a release is published that targets |
| 77 | + publish-design-tokens-github-packages-next: |
| 78 | + name: Publish @bcgov/design-tokens@next to GitHub Packages |
| 79 | + # Publish a `next` version to GitHub Packages on PR merge to main branch. |
| 80 | + if: ${{ github.event.pull_request.merged == true && github.repository == 'bcgov/design-system' }} |
| 81 | + permissions: |
| 82 | + packages: write |
| 83 | + runs-on: ubuntu-latest |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Checkout code |
| 87 | + uses: actions/checkout@v6 |
| 88 | + |
| 89 | + - name: Read .nvmrc |
| 90 | + run: echo "GITHUB_NVMRC_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV |
| 91 | + working-directory: ./packages/design-tokens |
| 92 | + |
| 93 | + - name: Set up Node.js |
| 94 | + uses: actions/setup-node@v6 |
| 95 | + with: |
| 96 | + node-version: ${{ env.GITHUB_NVMRC_VERSION }} |
| 97 | + |
| 98 | + - name: Install dependencies |
| 99 | + run: npm install |
| 100 | + working-directory: ./packages/design-tokens |
| 101 | + |
| 102 | + - name: Install jq |
| 103 | + run: sudo apt-get install -y jq |
| 104 | + |
| 105 | + - name: Run build script |
| 106 | + run: npm run build |
| 107 | + working-directory: ./packages/design-tokens |
| 108 | + |
| 109 | + - name: Prepare npm package for publishing |
| 110 | + run: npm run prepare-npm-package |
| 111 | + working-directory: ./packages/design-tokens |
| 112 | + |
| 113 | + # Use `jq` to change the package.json version to look like: |
| 114 | + # |
| 115 | + # <version in package.json>-pr<PR # that caused the workflow run> |
| 116 | + # |
| 117 | + # So package.json version v1.2.3 with a run caused by merging PR #456 to |
| 118 | + # `main` causes the version of the package on npm to look like: |
| 119 | + # |
| 120 | + # 1.2.3-pr456 |
| 121 | + # |
| 122 | + # This is to ensure that it's easy to map an npm version to a particular PR. |
| 123 | + # |
| 124 | + - name: Update version in dist/package.json |
| 125 | + run: | |
| 126 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 127 | + CURRENT_VERSION=$(jq -r '.version' package.json) |
| 128 | + NEW_VERSION="${CURRENT_VERSION}-pr${PR_NUMBER}" |
| 129 | + jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp.json && mv tmp.json package.json |
| 130 | + shell: bash |
| 131 | + working-directory: ./packages/design-tokens/dist |
| 132 | + |
| 133 | + - name: Publish to npm @next |
| 134 | + run: npm publish --tag next --registry=https://npm.pkg.github.com/ |
| 135 | + working-directory: ./packages/design-tokens/dist |
| 136 | + |
| 137 | + publish-design-tokens-npm-latest: |
| 138 | + name: Publish @bcgov/design-tokens@latest to npm |
| 139 | + # Publish a `latest` version to npm only when a release is published that targets |
79 | 140 | # the design tokens package via a tag like: |
80 | 141 | # @bcgov/design-tokens@v1.2.3 |
81 | 142 | if: ${{ github.event_name == 'release' && contains(github.event.release.tag_name, 'bcgov/design-tokens') }} |
| 143 | + permissions: |
| 144 | + id-token: write # Required for OIDC |
82 | 145 | runs-on: ubuntu-latest |
83 | 146 |
|
84 | 147 | steps: |
@@ -110,3 +173,42 @@ jobs: |
110 | 173 | - name: Publish to npm @latest |
111 | 174 | run: npm publish --tag latest |
112 | 175 | working-directory: ./packages/design-tokens/dist |
| 176 | + |
| 177 | + publish-design-tokens-github-packages-latest: |
| 178 | + name: Publish @bcgov/design-tokens@latest to GitHub Packages |
| 179 | + # Publish a `latest` version to GitHub Packages only when a release is published that targets |
| 180 | + # the design tokens package via a tag like: |
| 181 | + # @bcgov/design-tokens@v1.2.3 |
| 182 | + if: ${{ github.event_name == 'release' && contains(github.event.release.tag_name, 'bcgov/design-tokens') }} |
| 183 | + permissions: |
| 184 | + packages: write |
| 185 | + runs-on: ubuntu-latest |
| 186 | + |
| 187 | + steps: |
| 188 | + - name: Checkout code |
| 189 | + uses: actions/checkout@v6 |
| 190 | + |
| 191 | + - name: Read .nvmrc |
| 192 | + run: echo "GITHUB_NVMRC_VERSION=$(cat .nvmrc)" >> $GITHUB_ENV |
| 193 | + working-directory: ./packages/design-tokens |
| 194 | + |
| 195 | + - name: Set up Node.js |
| 196 | + uses: actions/setup-node@v6 |
| 197 | + with: |
| 198 | + node-version: ${{ env.GITHUB_NVMRC_VERSION }} |
| 199 | + |
| 200 | + - name: Install dependencies |
| 201 | + run: npm install |
| 202 | + working-directory: ./packages/design-tokens |
| 203 | + |
| 204 | + - name: Run build script |
| 205 | + run: npm run build |
| 206 | + working-directory: ./packages/design-tokens |
| 207 | + |
| 208 | + - name: Prepare npm package for publishing |
| 209 | + run: npm run prepare-npm-package |
| 210 | + working-directory: ./packages/design-tokens |
| 211 | + |
| 212 | + - name: Publish to GitHub Packages @latest |
| 213 | + run: npm publish --tag latest --registry=https://npm.pkg.github.com/ |
| 214 | + working-directory: ./packages/design-tokens/dist |
0 commit comments