Skip to content

Commit

Permalink
fix(nx-monorepo): release workflow
Browse files Browse the repository at this point in the history
- skip tests during release
- try to fix git tag permissions
  • Loading branch information
JeremyJonas committed May 23, 2023
1 parent 2bbf497 commit 874b9e2
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 27 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
NX_BRANCH: mainline
NX_RUN_GROUP: ${{ github.run_id }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_CLOUD_NO_TIMEOUTS: true
# GITHUB
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
Expand All @@ -39,6 +40,7 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
with:
Expand All @@ -50,18 +52,9 @@ jobs:
- name: PDK Init
uses: ./.github/actions/pdk-init
- name: Build
run: NX_CLOUD_NO_TIMEOUTS=true pnpm build
run: pnpm build
- name: Release
run: pnpm release
- name: Check for mutations
run: git diff --ignore-space-at-eol --exit-code
- name: Tag last-release
shell: bash
run: |
git tag -f last-release
git push origin last-release --force
- name: Print release tags
run: git tag --list --contains `git rev-parse HEAD`
- name: Upload docs artifact
uses: actions/upload-artifact@v2
with:
Expand Down
16 changes: 15 additions & 1 deletion .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/aws-arch/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/cdk-graph-plugin-diagram/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/cdk-graph/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/cloudscape-react-ts-website/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/identity/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/nx-monorepo/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 40 additions & 5 deletions packages/nx-monorepo/src/components/release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export class NxRelease extends Component {
*/
nxArgs?: string[];

/**
* Indicates if test task is skipping during release build.
*
* @default true
*/
skipTestDuringBuild: boolean = true;

constructor(project: Project) {
// Make sure only being added to the root project.
if (project.root !== project) {
Expand Down Expand Up @@ -74,6 +81,17 @@ export class NxRelease extends Component {
this.lastReleaseTag
} --nx-bail --output-style=stream ${(this.nxArgs || []).join(" ")}`;

const buildTask = this.project.addTask("release:build", {
env: {
SKIP_TEST: "true",
},
exec: NodePackageUtils.command.exec(
NodePackageUtils.resolvePackageManager(this.project),
"nx run-many --target=build --output-style=stream --nx-bail",
...(this.nxArgs || [])
),
});

const releaseTask = this.project.addTask("release", {
steps: [
{
Expand All @@ -99,11 +117,7 @@ export class NxRelease extends Component {
},
{
// rebuild everything after versioning
exec: NodePackageUtils.command.exec(
NodePackageUtils.resolvePackageManager(this.project),
"nx run-many --target=build --output-style=stream --nx-bail",
...(this.nxArgs || [])
),
exec: buildTask.name,
},
{
// create github releases
Expand All @@ -129,6 +143,8 @@ export class NxRelease extends Component {
exec: `git tag -f ${this.lastReleaseTag} && git push origin ${this.lastReleaseTag} --force`,
condition: `[ "\${CI:-false}" = "true" ]`,
});
// print all local tags for this release
tagTask.exec("git tag --list --contains `git rev-parse HEAD`");
releaseTask.spawn(tagTask);

const initTask = this.project.addTask("release:init", {
Expand Down Expand Up @@ -181,6 +197,13 @@ export class NxReleaseProject extends Component {
*/
stable?: boolean;

/**
* Indicates if test task is skipping during release build.
*
* @default {boolean} {@link NxRelease.skipTestDuringBuild}
*/
skipTestDuringBuild?: boolean;

constructor(project: Project) {
// Make sure we only ever have 1 instance of NxReleaseProject component per project
if (NxReleaseProject.of(project)) {
Expand Down Expand Up @@ -373,6 +396,18 @@ export class NxReleaseProject extends Component {
),
condition: `[ "\${CI:-false}" = "true" ] && [ -f "${RELEASE_ENV}" ]`,
});

if (
this.skipTestDuringBuild === true ||
(this.skipTestDuringBuild == null && release.skipTestDuringBuild === true)
) {
const condition =
(this.project.testTask.condition
? `${this.project.testTask.condition} && `
: "") + '[ "${SKIP_TEST:-false}" = "true" ]';
// @ts-ignore - private
this.project.testTask.condition = condition;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/open-api-gateway/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/pdk-nag/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/pipeline/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/static-website/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/type-safe-api/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 874b9e2

Please sign in to comment.