|
| 1 | +# Fundamental-ngx - Continuous Integration |
| 2 | + |
| 3 | +At fundamental-ngx we have two main CI workflows: |
| 4 | + |
| 5 | +- Create Release - Responsible for creating stable releases, and publishing them to npm, as well as creating |
| 6 | + RC and hotfix releases and publishing them to npm. |
| 7 | +- Pull Request Checks - Responsible for running all the checks on pull requests, |
| 8 | + such as linting, unit tests, and e2e tests. |
| 9 | + Both of them use [Nx Distributed task execution](https://nx.dev/core-features/distribute-task-execution) to run |
| 10 | + the tasks in parallel, and to cache the results of the tasks. |
| 11 | + |
| 12 | +## Create Release |
| 13 | + |
| 14 | +Create release is triggered when a new commit is pushed to the `main` branch or `tmp_hotfix_branch` branch. |
| 15 | +Commit message is very important, because on it might depend on the versioning of the release. |
| 16 | +In General, we use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) to determine the versioning |
| 17 | +of the release, and pipeline determines what should be the next version, but manually defining the version |
| 18 | +through CLI is also possible. |
| 19 | +For more information about the versioning, see [Versioning](README.md#versioning). |
| 20 | + |
| 21 | +For detailed information about the usage of the pipeline, see [Create Release](README.md#creation-of-the-release). |
| 22 | + |
| 23 | +Create release workflow consists of multiple jobs: |
| 24 | + |
| 25 | +- Nx Cloud Agents fire up - Runs always |
| 26 | +- Nx Cloud Run initialization - Runs always |
| 27 | +- Release Creation - Runs always |
| 28 | +- Github Pages Deployment - Runs only when the release is meant to be `latest` |
| 29 | +- Nx Cloud Run finalization - Runs always, even if something fails somewhere or if the pipeline is canceled. |
| 30 | + |
| 31 | +For explanation, we will be explaining `Release Creation` and `Github Pages Deployment` jobs, about the |
| 32 | +other jobs, you can read in the [Nx Cloud documentation](https://nx.dev/nx-cloud/intro/what-is-nx-cloud). |
| 33 | + |
| 34 | +### Release Creation |
| 35 | + |
| 36 | +So, `Release Creation` job consists of multiple tasks: |
| 37 | + |
| 38 | +- Checkout - Checks out the code from the repository. |
| 39 | +- Setup - Sets up the environment for the pipeline, such as installing dependencies, and setting up the cache. |
| 40 | +- Version bump - Determines the version of the release, based on the release type and the commit message. |
| 41 | + It is triggered conditionally, only if the commit message is not `chore(release): publish`, in which case, |
| 42 | + the version is not bumped, and the release is published with the current version. This is done to support |
| 43 | + manual releases, which are sometimes necessary. Bump outputs `newVersion`(the semantic version), |
| 44 | + `isPrerelease`(boolean, whether the release is prerelease or not), and `releaseTag`(the tag which should be used |
| 45 | + for the npm, it is one of `latest`, `prerelease`, `hotfix` or `ng*`, where `*` is the major version of the Angular |
| 46 | + which is supported by the build). |
| 47 | +- Get Release Tags - Depending on the `releaseTag` from the previous step, it gets the tags which should be used |
| 48 | + for the npm and github releases. For example |
| 49 | + - if the `releaseTag` is `latest`, then the tags will be `@latest` for npm and `isPrerelease` for github will be false, since it is not a prerelease. |
| 50 | + - If the `releaseTag` is `hotfix` |
| 51 | + - if the given version is higher than the one on `main` branch, then the tags will be `@latest` for the npm and |
| 52 | + `isPrerelease` for github will be false, since it is not a prerelease. |
| 53 | + - if the given version is lower than latest release, then the tags will be `@hotfix` for the npm and `isPrerelease` |
| 54 | + for github will be false, since the release is a hotfix and technically it is a release, but not the latest one, |
| 55 | + just the downport to the release, which is before the `latest`, but after the last build of the previous Angular build. |
| 56 | + - if the `releaseTag` is `prerelease`, then the tags will be `@prerelease` for the npm and `isPrerelease` for github will be true, since the release is a |
| 57 | + prerelease. |
| 58 | + - if the `releaseTag` is `ng*`, then the tags will be `@ng*` for the npm and `isPrerelease` for github will be false, since the release is not a prerelease. |
| 59 | +- Update using Lerna - If commit message does not contain the `chore(release): publish` message, then the version |
| 60 | + is not bumped yet on the repository, and it is done in this step. It uses [Lerna](https://lerna.js.org/) to update |
| 61 | + the version of the packages, and to update the dependencies between the packages. It also updates the changelog |
| 62 | + of the packages. It uses the `newVersion` from the `Version bump` step. |
| 63 | +- Lint and Build - Task has two jobs, one is to lint the code, and the other is to build the code. It is done in |
| 64 | + parallel, and the results are cached, so that the next time the pipeline is run, it will not have to run the tasks |
| 65 | + again, but will use the cached results. It uses [Nx Distributed task execution](https://nx.dev/core-features/distribute-task-execution) |
| 66 | + to run the tasks in parallel, and to cache the results of the tasks. |
| 67 | +- Pack - Packs the packages into the tarballs, which will be published to npm. It also does the `typedoc` extractions |
| 68 | + and replaces placeholders in the output packages, as well as the `README.md` files. This step also compiles the |
| 69 | + schematics from ts to js and copies them to the output packages. |
| 70 | +- Publish - Publishes the packages to npm. It uses the `npm` output from the `Get Release Tags` step for the tags. |
| 71 | +- Push changes - Pushes the changes to the repository, if the update happened on the CI and not on the user's machine, |
| 72 | + before the pipeline was triggered. |
| 73 | +- Generate Release Body - Generates the release body, which will be used for the github release. It uses the |
| 74 | + [Conventional-changelog](https://www.npmjs.com/package/conventional-changelog) to generate the release body. |
| 75 | + What this action does is that from the last release tag(`vX.Y.Z`), it gets the first previous release, which is |
| 76 | + the same type of the release and generates the changelog from the commits between the two releases. This means that |
| 77 | + if the last release tag was `v0.40.0-rc-9`, it will find the first previous release, which is also a prerelease, |
| 78 | + which would be `v0.40.0-rc-8`, and will generate the changelog from the commits between the two releases. If the |
| 79 | + last release tag was `v0.40.0`, it will find the first previous release, which is not a prerelease, which would be |
| 80 | + `v0.39.*`, and will generate the changelog from the commits between the two releases. This ensures that when the |
| 81 | + `stable` release is released, release notes contain all the changes from the previous `prereleases`, and when the |
| 82 | + `prerelease` is released, it contains only the things that went into the `prerelease`. |
| 83 | +- Create Release - Creates the github release. It uses the `gh` output from the `Get Release Tags` step for determining |
| 84 | + if the release is a prerelease or not, and for the tag which should be used for the github release. The release body |
| 85 | + will be taken from the `Generate Release Body` step. |
| 86 | + |
| 87 | +### Github Pages Deployment |
| 88 | + |
| 89 | +`Github Pages Deployment` job is triggered only when the release is meant to be `latest`, it just checks out the code |
| 90 | +which will be deployed to the github pages, and deploys it to the github pages. |
| 91 | + |
| 92 | +## Pull Request checks |
| 93 | + |
| 94 | +Pull request checks are run on every pull request, and they are run on the `pull_request` event. They ensure that the |
| 95 | +introduced changes are valid, and that they do not break anything. Just like `Create Release` workflow, they run using |
| 96 | +the Nx Cloud Agents. It has two main jobs: |
| 97 | + |
| 98 | +- Run affected Build, Lint and test commands |
| 99 | +- Run affected E2E commands |
| 100 | + |
| 101 | +### Run affected Build, Lint and test commands |
| 102 | + |
| 103 | +During this job, the following tasks are run: |
| 104 | + |
| 105 | +- Commit lint - Lints the commit message, to ensure that the commit messages follow conventional commit format. |
| 106 | +- Build, Lint and test commands - Runs the build, lint and test commands on the affected projects. It uses the |
| 107 | + [Nx Affected commands](https://nx.dev/packages/nx/documents/affected#affected) to determine which projects are affected by the changes |
| 108 | + in the pull request, and then runs the commands on the affected projects. It also caches the results of the commands, |
| 109 | + so that the next time the pipeline is run, it will not have to run the tasks again, but will use the cached results. |
| 110 | + It uses [Nx Distributed task execution](https://nx.dev/core-features/distribute-task-execution) to run the tasks in |
| 111 | + parallel, and to cache the results of the tasks. |
| 112 | +- Format check - Checks if the code is formatted correctly. Internally it uses many different static code linters, but |
| 113 | + main thing is that it uses [`nx format:check`](https://nx.dev/packages/nx/documents/format-check) to check only the |
| 114 | + files which are affected by the changes in the pull request. |
| 115 | + |
| 116 | +### Run affected E2E commands |
| 117 | + |
| 118 | +During this job, the following tasks are run: |
| 119 | + |
| 120 | +- Firebase preview - Deploys PR version of the documentation to the firebase, so that it can be previewed. |
| 121 | +- E2E tests on firebase - If firebase preview deployment was successful, and we have a URL, which we could test |
| 122 | + in headless chrome, then we run the e2e tests on the firebase preview deployment. This gives us ability to use multiple |
| 123 | + agents to run our tests in truly parallel way, and to have a clean environment for each test run. |
| 124 | +- E2E tests on local - If firebase preview deployment was not successful, then we run the e2e tests on the local |
| 125 | + headless chrome. This task is not preferred since it is not run in parallel. |
0 commit comments