Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: targetCommitish now compares commits, not commitish #3

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
id: test-run
uses: ./
with:
release_version_regexp: 'test-v?(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+).*$'
release_version_regexp: '^test-v?(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+).*$'

- name: Assert placeholder
uses: nick-fields/assert-action@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Get Next Release Version Action

[![CI](https://github.com/datalens-tech/get-next-release-version-action/workflows/Check%20PR/badge.svg)](https://github.com/ovsds/get-next-release-version-action/actions?query=workflow%3A%22%22Check+PR%22%22)
[![CI](https://github.com/datalens-tech/get-next-release-version-action/workflows/Check%20PR/badge.svg)](https://github.com/datalens-tech/get-next-release-version-action/actions?query=workflow%3A%22%22Check+PR%22%22)
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Get%20Next%20Release%20Version-blue.svg)](https://github.com/marketplace/actions/get-next-release-version)

Get Next Release Version Action
Expand Down
24 changes: 19 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ class GitHubClient {
}));
});
}
compareCommits(owner, repo, base, head) {
return __awaiter(this, void 0, void 0, function* () {
const data = yield this.octokitClient.repos.compareCommits({
owner,
repo,
base,
head,
});
return data.data.status;
});
}
getLatestRelease(owner, repo, targetCommitish, prerelease, releaseVersionRegexp) {
return __awaiter(this, void 0, void 0, function* () {
let page = 1;
Expand All @@ -51,16 +62,19 @@ class GitHubClient {
const releases = yield this.getReleases(owner, repo, perPage, page);
this.logger(`Fetched ${releases.length} releases from page ${page}`);
for (const release of releases) {
if (targetCommitish !== "" && release.targetCommitish !== targetCommitish) {
this.logger(`Skipping release ${release.tagName} because target commitish does not match`);
continue;
if (targetCommitish !== "") {
const status = yield this.compareCommits(owner, repo, targetCommitish, release.tagName);
if (status !== "behind" && status !== "identical") {
this.logger(`Skipping release ${release.tagName} because it is not based on the target commitish(${targetCommitish})`);
continue;
}
}
if (prerelease !== null && release.prerelease !== prerelease) {
this.logger(`Skipping release ${release.tagName} because prerelease status does not match`);
this.logger(`Skipping release ${release.tagName} because prerelease status does not match, expected ${prerelease}, got ${release.prerelease}`);
continue;
}
if (!releaseVersionRegexp.test(release.tagName)) {
this.logger(`Skipping release ${release.tagName} because it does not match the version regexp`);
this.logger(`Skipping release ${release.tagName} because it does not match the version regexp(${releaseVersionRegexp})`);
continue;
}
return release;
Expand Down
30 changes: 25 additions & 5 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class GitHubClient {
}));
}

async compareCommits(owner: string, repo: string, base: string, head: string): Promise<string> {
const data = await this.octokitClient.repos.compareCommits({
owner,
repo,
base,
head,
});

return data.data.status;
}

async getLatestRelease(
owner: string,
repo: string,
Expand All @@ -77,18 +88,27 @@ class GitHubClient {
this.logger(`Fetched ${releases.length} releases from page ${page}`);

for (const release of releases) {
if (targetCommitish !== "" && release.targetCommitish !== targetCommitish) {
this.logger(`Skipping release ${release.tagName} because target commitish does not match`);
continue;
if (targetCommitish !== "") {
const status = await this.compareCommits(owner, repo, targetCommitish, release.tagName);
if (status !== "behind" && status !== "identical") {
this.logger(
`Skipping release ${release.tagName} because it is not based on the target commitish(${targetCommitish})`,
);
continue;
}
}

if (prerelease !== null && release.prerelease !== prerelease) {
this.logger(`Skipping release ${release.tagName} because prerelease status does not match`);
this.logger(
`Skipping release ${release.tagName} because prerelease status does not match, expected ${prerelease}, got ${release.prerelease}`,
);
continue;
}

if (!releaseVersionRegexp.test(release.tagName)) {
this.logger(`Skipping release ${release.tagName} because it does not match the version regexp`);
this.logger(
`Skipping release ${release.tagName} because it does not match the version regexp(${releaseVersionRegexp})`,
);
continue;
}

Expand Down
Loading