Skip to content

Commit

Permalink
chore(lerna): aggressive patch bump (#1163)
Browse files Browse the repository at this point in the history
* fix(lerna): aggressive patch bump

* fix(lerna): aggressive patch bump keeping constant version

* fix(lerna): aggressive patch bump keeping constant version

* fix(lerna): unpredictable master branch versioning

* chore(fix): switch to patch from conventional commit

* chore(doc): update the docs

* chore(contribution.md): fix documentation

* fix(release): add custom script to remove rc tag

* fix(scripts): lint errors

* fix(scripts): lint errors

* fix(scripts): lint errors

* fix(scripts): lint errors

* fix(scripts): lint errors

* feat(release): add rc tag removal script run

* fix(versioning): modify rc tag removing script and release.yaml

* fix(linting): modify rc tag removing script

* fix(contributing): add the mistakenly removed doc

* fix(contributing): add the mistakenly removed doc
  • Loading branch information
SudilHasithaCognite authored Dec 5, 2024
1 parent e18a440 commit df9fa83
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 21 deletions.
58 changes: 47 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ jobs:
run: yarn build

publish:
if: |-
${{
!contains(github.event.commits[0].message, '[skip-ci]') &&
(
startsWith(github.event.commits[0].message, 'fix:') ||
startsWith(github.event.commits[0].message, 'fix(') ||
startsWith(github.event.commits[0].message, 'feat:') ||
startsWith(github.event.commits[0].message, 'feat(') ||
contains(github.event.commits[0].message, '[release]')
if: ${{ !contains(github.event.head_commit.message, '[skip-ci]') &&
(
(github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, '[release]')) ||
(startsWith(github.ref, 'refs/heads/release-') &&
(startsWith(github.event.head_commit.message, 'fix:') ||
startsWith(github.event.head_commit.message, 'fix(') ||
startsWith(github.event.head_commit.message, 'feat:') ||
startsWith(github.event.head_commit.message, 'feat(') ||
contains(github.event.head_commit.message, '[release]')
)
)
)
}}
runs-on: ubuntu-latest
environment: CD
Expand Down Expand Up @@ -81,17 +83,51 @@ jobs:
- name: Build doc
run: yarn docs:bundle

# Remove rc tag in master branch when it is a [release] commit
- name: Remove RC tags
if: ${{ github.ref == 'refs/heads/master' && contains(github.event.head_commit.message, 'Merge pull request') && contains(github.event.head_commit.message, 'release-') && contains(github.event.head_commit.message, '[release]') }}
run: |
node scripts/remove-rc-tags.js
git config --global user.email "[email protected]"
git config --global user.name "Cognite CICD"
git add packages/*/package.json
git commit -m "chore: remove rc tags [skip-ci]"
git push origin master
- name: Lerna version
env:
GH_TOKEN: ${{ secrets.GH_LERNA_TOKEN }} # Temporary fix to make lerna able to push the new versions commit to master
GITHUB_TOKEN: ${{ secrets.GH_LERNA_TOKEN }} # Temporary fix to make lerna able to push the new versions commit to master
run: yarn lerna version --conventional-commits --conventional-prerelease --preid rc --create-release github --no-private --yes
run: |
if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then
EVENT_PATH_CONTENT=$(cat ${GITHUB_EVENT_PATH} | jq -r '.')
HEAD_COMMIT_MSG=$(echo $EVENT_PATH_CONTENT | jq -r '.head_commit.message')
MERGE_COMMIT_MSG=$(echo $EVENT_PATH_CONTENT | jq -r '.commits[-1].message')
if [[ "$HEAD_COMMIT_MSG" == *"Merge"* && "$HEAD_COMMIT_MSG" == *"release-"* && "$HEAD_COMMIT_MSG" == *"[release]"* ]] ||
[[ "$MERGE_COMMIT_MSG" == *"Merge"* && "$MERGE_COMMIT_MSG" == *"release-"* && "$MERGE_COMMIT_MSG" == *"[release]"* ]]; then
echo "Running major version bump for release merge"
yarn lerna version major --conventional-commits --create-release github --no-private --yes --force-publish
else
echo "Running conventional commit versioning on master"
yarn lerna version --conventional-commits --create-release github --no-private --yes
fi
elif [[ "${GITHUB_REF}" == refs/heads/release-* ]]; then
echo "Running pre-release versioning on release branch"
yarn lerna version --conventional-commits --conventional-prerelease --preid rc --create-release github --no-private --yes
fi
- name: Lerna Publish
if: contains(github.event.head_commit.message, '[release]')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: yarn lerna publish from-package --pre-dist-tag rc --yes --no-git-reset --no-verify-access
run: |
if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then
yarn lerna publish from-package --yes --no-git-reset --no-verify-access
elif [[ "${GITHUB_REF}" == refs/heads/release-* ]]; then
yarn lerna publish from-package --pre-dist-tag rc --yes --no-git-reset --no-verify-access
fi
# - name: Publish documentation
# uses: JamesIves/github-pages-deploy-action@releases/v3
Expand Down
24 changes: 15 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,22 @@ More details are documented in the [codegen README](packages/codegen/README.md).

## Pull request

Make a pull request from your branch to the main branch. When merging the pull request,
Make a pull request from your branch to the master branch. When merging the pull request,
only use squashing if the resulting squash commit can accurately describe the change as a single conventional commit.
Once the change is pushed to the main branch, it is time for a release.
Once the change is pushed to the master branch, it is time for a release.

## Releases & Versioning

Releases are done from the main branch, so when a pull request is merged,
Releases are done from the master branch, so when a pull request is merged,
CI/CD will run tests, and if successful, do deploys.
Documentation is built and deployed, and code snippets
are exported to the service contract repo as a pull request.

Updating and uploading npm packages only happens if the HEAD commit of the main branch
contains `[release]` in its description or the PR title starts with `feat` or `fix`.
Updating and uploading npm packages only happens if the HEAD commit of the master branch
contains `[release]` in its description and the PR title starts with `feat` or `fix`.
When CI/CD sees this, it will use lerna to update
package versions of changed packages based on commit messages, and add the
changes to the changelogs. The changes are comitted to the main branch
changes to the changelogs. The changes are comitted to the master branch
with the new versions as git tags, and the new package versions are uploaded to npm.

We restrict new npm releases to `[release]`-tagged commits because lerna is
Expand All @@ -93,7 +93,7 @@ cause a PATCH bump. Markdown files and tests are ignored, but changing anything
like a comment in a source file, will trigger a new version,
irrespective of conventional commits.

This does _not_ mean you should store unfinished work on the main branch.
This does _not_ mean you should store unfinished work on the master branch.
Another package may be ready for release, and once a `[release]`
commit is pushed, all changed packages are updated.
Repository administrators should be in control of `[release]` commits.
Expand All @@ -111,9 +111,15 @@ If you want to push the empty commit to master via a pull request,
use a squash merge (not rebase+ff). Otherwise GitHub will ignore the empty PR.

Also, keep in mind that the `[release]` commit has to be the HEAD of
main, and Github Action only runs on the HEAD. If HEAD has changed by the time
master, and Github Action only runs on the HEAD. If HEAD has changed by the time
the versioning happens, Github Action will fail.

In order to perform a major release by merging a release candidate branch to master by keeping the same major version in release candidate version.

- Create a PR from release-* to master
- Make a PR title and the message when merging to be ` chore(): details [release]`
- The release tag is to trigger the release of the package.

## Patching older major versions

If you need to backport a fix to a previous MAJOR version of a package,
Expand Down Expand Up @@ -234,4 +240,4 @@ The SDK will call this method when:

- The user calls `authenticate` on the client.
- The SDK receives a 401 from the API.
When multiple requests receives a 401, then only a single call to `oidcTokenProvider` will be invoked. All requests will wait for `oidcTokenProvider` to resolve/reject. If it's resolved, then all the requests will retry before returning the response to the SDK caller. However, if the resolved access token matches the original access token, then no retry will be performed.
When multiple requests receives a 401, then only a single call to `oidcTokenProvider` will be invoked. All requests will wait for `oidcTokenProvider` to resolve/reject. If it's resolved, then all the requests will retry before returning the response to the SDK caller. However, if the resolved access token matches the original access token, then no retry will be performed.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"**/*.test.ts"
],
"message": "chore(release): publish new package versions [skip ci]",
"allowBranch": "release-v10"
"allowBranch": ["master", "release-*"]
}
}
}
24 changes: 24 additions & 0 deletions scripts/remove-rc-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Remove -rc tag from release branch when it merge to master
const fs = require('node:fs');
const glob = require('glob');

// Retrive all pacakage.json file paths
const packageFilesPaths = glob.sync('packages/*/package.json');

// loop through each and remove rc tag
for (const packageFilePath of packageFilesPaths) {
//get the package content to json file
const packageJson = JSON.parse(fs.readFileSync(packageFilePath, 'utf-8'));

// check for rc, remove it, reassign the version and rewrite
if (packageJson.version?.includes('-rc')) {
// 6.0.0-rc.1 --> [6.0.0, -rc.1]
// 5.0.0 which then convert to 6.0.0 by release.yaml
majorVersion = Number.parseInt(packageJson.version.split('-rc')[0]) - 1;
packageJson.version = `${majorVersion}.0.0`;
fs.writeFileSync(
packageFilePath,
`${JSON.stringify(packageJson, null, 2)}\n`
);
}
}

0 comments on commit df9fa83

Please sign in to comment.