-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…rom-github Gets the latest version of Cake from GitHub
- Loading branch information
Showing
8 changed files
with
274 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,24 @@ jobs: | |
cake-version: tool-manifest | ||
script-path: ${{ env.script-directory }}/build.cake | ||
target: Test-Cake-Version | ||
- name: Get the latest Cake release from GitHub | ||
id: get-latest-cake-release | ||
uses: octokit/[email protected] | ||
with: | ||
route: GET /repos/cake-build/cake/releases/latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Set the EXPECTED_CAKE_VERSION environment variable | ||
shell: bash | ||
run: | | ||
version=$(echo ${{ fromJson(steps.get-latest-cake-release.outputs.data).tag_name }} | sed 's/v//') | ||
echo "EXPECTED_CAKE_VERSION=$version" >> $GITHUB_ENV | ||
- name: Run with the latest Cake version | ||
uses: ./ | ||
with: | ||
cake-version: latest | ||
script-path: ${{ env.script-directory }}/build.cake | ||
target: Test-Cake-Version | ||
- name: Run automatic bootstrapping of Cake modules (Cake >= 1.0.0) | ||
uses: ./ | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import * as http from '@actions/http-client'; | ||
import * as cakeRelease from '../src/cakeRelease'; | ||
|
||
describe('When retrieving the latest Cake version', () => { | ||
beforeAll(async () => { | ||
jest | ||
.spyOn(http.HttpClient.prototype, 'getJson') | ||
.mockImplementation(async () => ({ | ||
statusCode: 200, | ||
result: { | ||
tag_name: 'v1.0.0' | ||
}, | ||
headers: {} | ||
})); | ||
}); | ||
|
||
test('it should return the latest version number from GitHub', async () => { | ||
expect(await cakeRelease.getLatestVersion()).toBe('1.0.0'); | ||
}); | ||
}); | ||
|
||
describe('When retrieving the latest Cake version without the \'v\' prefix', () => { | ||
beforeAll(async () => { | ||
jest | ||
.spyOn(http.HttpClient.prototype, 'getJson') | ||
.mockImplementation(async () => ({ | ||
statusCode: 200, | ||
result: { | ||
tag_name: '1.0.0' | ||
}, | ||
headers: {} | ||
})); | ||
}); | ||
|
||
test('it should return the latest version number from GitHub', async () => { | ||
expect(await cakeRelease.getLatestVersion()).toBe('1.0.0'); | ||
}); | ||
}); | ||
|
||
describe('When failing to retrieve the latest Cake version due to a GitHub error', () => { | ||
beforeAll(async () => { | ||
jest | ||
.spyOn(http.HttpClient.prototype, 'getJson') | ||
.mockImplementation(async () => ({ | ||
statusCode: 500, | ||
result: {}, | ||
headers: {} | ||
})); | ||
}); | ||
|
||
test('it should return null', async () => { | ||
expect(await cakeRelease.getLatestVersion()).toBeNull(); | ||
}); | ||
|
||
test('it should log the fact that the GitHub API returned an error', async () => { | ||
const log = jest.spyOn(console, 'log'); | ||
await cakeRelease.getLatestVersion(); | ||
expect(log).toHaveBeenCalledWith('Could not determine the latest version of Cake. GitHub returned status code 500'); | ||
}); | ||
}); | ||
|
||
describe('When failing to retrieve the latest Cake version due to an empty response from GitHub', () => { | ||
beforeAll(async () => { | ||
jest | ||
.spyOn(http.HttpClient.prototype, 'getJson') | ||
.mockImplementation(async () => ({ | ||
statusCode: 200, | ||
result: {}, | ||
headers: {} | ||
})); | ||
}); | ||
|
||
test('it should return null', async () => { | ||
expect(await cakeRelease.getLatestVersion()).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('When failing to retrieve the latest Cake version due to a missing tag name in the GitHub response', () => { | ||
beforeAll(async () => { | ||
jest | ||
.spyOn(http.HttpClient.prototype, 'getJson') | ||
.mockImplementation(async () => ({ | ||
statusCode: 200, | ||
result: { | ||
tag_name: null | ||
}, | ||
headers: {} | ||
})); | ||
}); | ||
|
||
test('it should return null', async () => { | ||
expect(await cakeRelease.getLatestVersion()).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('When failing to retrieve the latest Cake version due to an empty tag name in the GitHub response', () => { | ||
beforeAll(async () => { | ||
jest | ||
.spyOn(http.HttpClient.prototype, 'getJson') | ||
.mockImplementation(async () => ({ | ||
statusCode: 200, | ||
result: { | ||
tag_name: '' | ||
}, | ||
headers: {} | ||
})); | ||
}); | ||
|
||
test('it should return null', async () => { | ||
expect(await cakeRelease.getLatestVersion()).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as http from '@actions/http-client'; | ||
|
||
export async function getLatestVersion(): Promise<string | null> { | ||
const release = await getLatestCakeReleaseFromGitHub(); | ||
return extractVersionNumber(release); | ||
} | ||
|
||
async function getLatestCakeReleaseFromGitHub(): Promise<GitHubRelease | null> { | ||
const client = new http.HttpClient('cake-build/cake-action'); | ||
const response = await client.getJson<GitHubRelease>('https://api.github.com/repos/cake-build/cake/releases/latest'); | ||
|
||
if (response.statusCode != 200) { | ||
console.log(`Could not determine the latest version of Cake. GitHub returned status code ${response.statusCode}`); | ||
return null; | ||
} | ||
|
||
return response.result; | ||
} | ||
|
||
function extractVersionNumber(release: GitHubRelease | null): string | null { | ||
return release?.tag_name?.replace(/^v/, '') || null; | ||
} | ||
|
||
interface GitHubRelease { | ||
tag_name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters