Skip to content

Commit

Permalink
fix(scripts): properly detect release commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed May 27, 2022
1 parent 32630ee commit 5c13be2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GENERATE_BOT }}
PR_NUMBER: ${{ github.event.number }}
HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}

- name: Spread generation to each repository
if: ${{ steps.pushGeneratedCode.exitcode == 0 && github.ref == 'refs/heads/main' }}
run: yarn workspace scripts spreadGeneration
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GENERATE_BOT }}
HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
7 changes: 3 additions & 4 deletions scripts/ci/codegen/pushGeneratedCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { getNbGitDiff } from '../utils';
import text from './text';

const PR_NUMBER = parseInt(process.env.PR_NUMBER || '0', 10);
const IS_RELEASE_COMMIT =
process.env.HEAD_COMMIT_MESSAGE?.startsWith(
text.commitPrepareReleaseMessage
) || false;

async function isUpToDate(baseBranch: string): Promise<boolean> {
await run('git fetch origin');
Expand All @@ -28,6 +24,9 @@ export async function pushGeneratedCode(): Promise<void> {

const baseBranch = await run('git branch --show-current');
const isMainBranch = baseBranch === MAIN_BRANCH;
const IS_RELEASE_COMMIT = (await run('git log -1 --format="%s"')).startsWith(
text.commitPrepareReleaseMessage
);
console.log(`Checking codegen status on '${baseBranch}'.`);

const nbDiff = await getNbGitDiff({
Expand Down
10 changes: 4 additions & 6 deletions scripts/ci/codegen/spreadGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import { getNbGitDiff } from '../utils';

import text from './text';

const IS_RELEASE_COMMIT =
process.env.HEAD_COMMIT_MESSAGE?.startsWith(
text.commitPrepareReleaseMessage
) || false;

export function decideWhereToSpread(commitMessage: string): Language[] {
if (commitMessage.startsWith('chore: release')) {
return [];
Expand Down Expand Up @@ -84,10 +79,13 @@ async function spreadGeneration(): Promise<void> {
.map((coAuthor) => coAuthor.trim())
.filter(Boolean);

const IS_RELEASE_COMMIT = lastCommitMessage.startsWith(
text.commitPrepareReleaseMessage
);
const commitMessage = cleanUpCommitMessage(lastCommitMessage);
const langs = decideWhereToSpread(lastCommitMessage);

// At this point, we know the release will happen on every clients
// At this point, we know the release will happen on at least one client
// So we want to set the released tag at the monorepo level too.
if (IS_RELEASE_COMMIT) {
// remove old `released` tag
Expand Down

0 comments on commit 5c13be2

Please sign in to comment.