diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 7840fd4..44c549f 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -22,7 +22,7 @@ jobs: id: test-run uses: ./ with: - release_version_regexp: 'test-v?(?[0-9]+)\.(?[0-9]+)\.(?[0-9]+).*$' + release_version_regexp: '^test-v?(?[0-9]+)\.(?[0-9]+)\.(?[0-9]+).*$' - name: Assert placeholder uses: nick-fields/assert-action@v2 diff --git a/README.md b/README.md index 053a404..ea7edfc 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/index.js b/dist/index.js index 3510694..c8538ac 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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; @@ -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; diff --git a/src/action.ts b/src/action.ts index 54c1a69..99f0a67 100644 --- a/src/action.ts +++ b/src/action.ts @@ -62,6 +62,17 @@ class GitHubClient { })); } + async compareCommits(owner: string, repo: string, base: string, head: string): Promise { + const data = await this.octokitClient.repos.compareCommits({ + owner, + repo, + base, + head, + }); + + return data.data.status; + } + async getLatestRelease( owner: string, repo: string, @@ -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; }