Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
josephperrott committed Aug 26, 2021
1 parent d8ae9c7 commit ab6451c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions tools/local-actions/changelog/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {ANGULAR_ROBOT, getAuthTokenFor} from '../../../../github-actions/utils';
import {GithubConfig, setConfig} from '../../../../ng-dev/utils/config';
import {ReleaseConfig} from '../../../../ng-dev/release/config/index';

/** THe name of the branch used for tracking the last time the changlog was generated. */
const releaseBranchName = 'release';
/** The tag used for tracking the last time the changlog was generated. */
const lastChangelogTag = 'most-recent-changelog-generation';
/** Marker comment used to split the changelog into a list of distinct changelog entries. */
const splitMarker = '\n<!-- CHANGELOG SPLIT MARKER -->\n';
/** The commit message used for the changes to the CHANGELOG. */
Expand Down Expand Up @@ -53,15 +53,12 @@ async function run(): Promise<void> {
const changelogFile = join(git.baseDir, 'CHANGELOG.md');
/** The full path of the changelog */
const changelogArchiveFile = join(git.baseDir, 'CHANGELOG_ARCHIVE.md');
/**
* The sha of the latest commit on the branch used for tracking when the last changelog generation
* occured.
*/
let releaseTag = getLatestRefFromUpstream(releaseBranchName);
/** The sha of the commit when the changelog was most recently generated. */
let lastChangelogRef = getLatestRefFromUpstream(lastChangelogTag);
/** The sha of the latest commit on the main branch. */
let latestRef = getLatestRefFromUpstream(git.mainBranchName);
/** The release notes generation object. */
const releaseNotes = await ReleaseNotes.forRange(getTodayAsSemver(), releaseTag, latestRef);
const releaseNotes = await ReleaseNotes.forRange(getTodayAsSemver(), lastChangelogRef, latestRef);

if ((await releaseNotes.getCommitCountInReleaseNotes()) === 0) {
console.log('No release notes are needed as no commits would be included.');
Expand Down Expand Up @@ -94,13 +91,11 @@ async function run(): Promise<void> {
writeAndAddToGit(changelogFile, changelog.join(splitMarker));

// Commit the new changelog(s) and push the changes to github.
git.run(['commit', '-q', '--no-verify', '-m', commitMessage]);
git.run([
'push',
git.getRepoGitUrl(),
`HEAD:refs/heads/${releaseBranchName}`,
`HEAD:refs/heads/${git.mainBranchName}`,
]);
git.run(['commit', '--no-verify', '-m', commitMessage]);
git.run(['push', git.getRepoGitUrl(), `HEAD:refs/heads/${git.mainBranchName}`]);
// A force push is used to update the tag git does not expect it to move and a force is neccessary
// to update it from its old sha.
git.run(['push', '-f', git.getRepoGitUrl(), `HEAD:refs/tags/${lastChangelogTag}`]);
}

/** Write the contents to the provided file and add it to git staging. */
Expand All @@ -114,7 +109,7 @@ function writeAndAddToGit(filePath: string, contents: string) {
function getLatestRefFromUpstream(branchOrTag: string) {
try {
const git = AuthenticatedGitClient.get();
git.runGraceful(['fetch', '-q', git.getRepoGitUrl(), branchOrTag, '--depth=250']);
git.runGraceful(['fetch', git.getRepoGitUrl(), branchOrTag, '--depth=250']);
return git.runGraceful(['rev-parse', 'FETCH_HEAD']).stdout.trim();
} catch {
core.error(`Unable to retrieve '${branchOrTag}' from upstream`);
Expand Down

0 comments on commit ab6451c

Please sign in to comment.