|
| 1 | +name: v10 - Version |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - v10 |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + version: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: github.repository == 'carbon-design-system/carbon' |
| 16 | + timeout-minutes: 60 |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 19 | + with: |
| 20 | + fetch-depth: '0' |
| 21 | + fetch-tags: true |
| 22 | + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 23 | + - name: Use Node.js version from .nvmrc |
| 24 | + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 25 | + with: |
| 26 | + node-version-file: '.nvmrc' |
| 27 | + registry-url: 'https://registry.npmjs.org' |
| 28 | + - name: Install dependencies |
| 29 | + run: yarn install --immutable --immutable-cache --check-cache |
| 30 | + - name: Build project |
| 31 | + run: yarn build |
| 32 | + - name: Run Continuous Integration checks |
| 33 | + run: yarn ci-check |
| 34 | + |
| 35 | + - name: Check if commit is a release commit |
| 36 | + id: check-commit |
| 37 | + uses: actions/github-script@v7 |
| 38 | + with: |
| 39 | + script: | |
| 40 | + const commitMessage = context.payload.head_commit?.message || ''; |
| 41 | + core.info(`Latest commit message: "${commitMessage}"`); |
| 42 | + const isReleaseCommit = commitMessage.includes('chore(release): v10.'); |
| 43 | + core.setOutput('is_release_commit', isReleaseCommit); |
| 44 | +
|
| 45 | + - name: Bump package versions if commit is not a release commit |
| 46 | + if: steps.check-commit.outputs.is_release_commit != 'true' |
| 47 | + run: | |
| 48 | + yarn lerna version prerelease --force-publish --no-push --no-git-tag-version --preid community --yes |
| 49 | +
|
| 50 | + - name: Get latest v10 tag and determine next appropriate tag |
| 51 | + id: calculate-tag |
| 52 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 53 | + with: |
| 54 | + script: | |
| 55 | + const { execSync } = require('child_process'); |
| 56 | + const semver = require('semver'); |
| 57 | +
|
| 58 | + // Get all tags starting with v10 |
| 59 | + const output = execSync("git tag --list 'v10.*.*'", { encoding: 'utf8' }); |
| 60 | + const tags = output.trim().split('\n').filter(Boolean); |
| 61 | +
|
| 62 | + if (tags.length === 0) { |
| 63 | + core.setFailed('No v10 tags found.'); |
| 64 | + return; |
| 65 | + } |
| 66 | +
|
| 67 | + // Sort with semver |
| 68 | + const sorted = tags.sort((a, b) => semver.rcompare(a, b)); |
| 69 | + const latest = sorted[0]; |
| 70 | +
|
| 71 | + // The third argument to semver.inc(version, release, identifier) |
| 72 | + // is crucial. 'prerelease' tells semver to increment the final |
| 73 | + // numeric part of the prerelease tag. 'community' is passed as the |
| 74 | + // prerelease identifier to continue the correct sequence. |
| 75 | + // This ensures v10.60.3-community.1 is bumped to |
| 76 | + // v10.60.3-community.2, for example. |
| 77 | + const next = semver.inc(latest, 'prerelease', 'community'); |
| 78 | +
|
| 79 | + // semver.inc() returns the version without the 'v' prefix. Here |
| 80 | + // we add it back to ensure the final tag is prefixed with 'v'. |
| 81 | + const nextTag = `v${next}`; |
| 82 | +
|
| 83 | + core.info(`Latest v10 tag: ${latest}`); |
| 84 | + core.info(`Next v10 tag: ${next}`); |
| 85 | + core.setOutput('latestTag', latest); |
| 86 | + core.setOutput('nextTag', next); |
| 87 | +
|
| 88 | + # TODO dry run this as a test to see what we'd have |
| 89 | + - name: If commit is a release commit, tag it |
| 90 | + if: steps.check-commit.outputs.is_release_commit == 'true' |
| 91 | + run: | |
| 92 | + echo ${{ steps.calculate-tag.outputs.nextTag }} ${{ steps.calculate-tag.outputs.nextTag }} |
| 93 | + # run: | |
| 94 | + # git tag -a ${{ steps.calculate-tag.outputs.nextTag }} -m '${{ steps.calculate-tag.outputs.nextTag }}' && git push upstream ${{ steps.calculate-tag.outputs.nextTag }} |
| 95 | + |
| 96 | + - name: Generate token |
| 97 | + # Do not generate token for release commits |
| 98 | + if: steps.check-commit.outputs.is_release_commit != 'true' |
| 99 | + uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a #v2.1.0 |
| 100 | + id: generate_token |
| 101 | + with: |
| 102 | + app_id: ${{ secrets.APP_ID }} |
| 103 | + private_key: ${{ secrets.APP_PRIVATE_KEY }} |
| 104 | + |
| 105 | + - name: Create Pull Request |
| 106 | + # Do not create PR for release commits |
| 107 | + if: steps.check-commit.outputs.is_release_commit != 'true' |
| 108 | + uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 |
| 109 | + with: |
| 110 | + branch: 'release/${{ steps.calculate-tag.outputs.nextTag }}' |
| 111 | + commit-message: |
| 112 | + 'chore(release): ${{ steps.calculate-tag.outputs.nextTag }}' |
| 113 | + delete-branch: true |
| 114 | + base: 'v10' |
| 115 | + title: 'chore(release): ${{ steps.calculate-tag.outputs.nextTag }}' |
| 116 | + token: ${{ steps.generate_token.outputs.token }} |
| 117 | + body: | |
| 118 | + Automated release PR for ${{ steps.calculate-tag.outputs.nextTag }} |
| 119 | +
|
| 120 | + **Checklist** |
| 121 | +
|
| 122 | + - [ ] Verify package version bumps are accurate |
| 123 | + - [ ] Verify CI passes as expected |
0 commit comments