Skip to content

Commit

Permalink
Merge pull request #92 from MagnusOpera/feature/prerelease
Browse files Browse the repository at this point in the history
Install latest prerelease assets
  • Loading branch information
jaxxstorm authored Nov 10, 2024
2 parents cbf139e + afbdcd5 commit 97ca0c8
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 31 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,18 @@ jobs:
chmod: 0755
cache: enable
- run: wit-bindgen-wrpc --version

terrabuild:
strategy:
matrix:
runs-on: ["ubuntu-latest"]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm run build
- uses: ./
with:
repo: magnusopera/terrabuild
prerelease: true
- run: terrabuild version
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ steps:
repo: go-task/task
```
### Grab the Latest PreRelease Version
```yaml
# ...
steps:
- name: Install go-task
uses: jaxxstorm/action-install-gh-release@v1.10.0
with: # Grab the latest version
repo: go-task/task
prerelease: true
```
### Grab Specific Tags
```yaml
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
description: "tag containing binary to install"
default: latest
required: true
prerelease:
description: "considerer prerelease for latest tag"
default: "false"
required: false
platform:
description: "OS Platform to match in release package. Specify this parameter if the repository releases do not follow a normal convention otherwise it will be auto-detected."
required: false
Expand Down
62 changes: 46 additions & 16 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function run() {
}
let tag = core.getInput("tag");
tag = !tag ? "latest" : tag;
let prerelease = core.getInput("prerelease") === "true";
const cacheEnabled = (core.getInput("cache") === "enable")
&& tag !== "latest"
&& tag !== "";
Expand Down Expand Up @@ -170,19 +171,48 @@ function run() {
return;
}
}
let getReleaseUrl;
if (tag === "latest") {
getReleaseUrl = yield octokit.rest.repos.getLatestRelease({
owner: owner,
repo: repoName,
});
}
else {
getReleaseUrl = yield octokit.rest.repos.getReleaseByTag({
owner: owner,
repo: repoName,
tag: tag,
});
const getRelease = () => __awaiter(this, void 0, void 0, function* () {
if (tag === "latest") {
if (prerelease) {
let page = 1;
const per_page = 30;
while (true) {
const { data: releases } = yield octokit.rest.repos.listReleases({
owner: owner,
repo: repoName,
per_page,
page
});
const release = releases.find(release => release.prerelease);
if (!!release) {
return release;
}
if (releases.length < per_page) {
return undefined;
}
++page;
}
}
else {
const release = yield octokit.rest.repos.getLatestRelease({
owner: owner,
repo: repoName,
});
return release.data;
}
}
else {
const release = yield octokit.rest.repos.getReleaseByTag({
owner: owner,
repo: repoName,
tag: tag,
});
return release.data;
}
});
let release = yield getRelease();
if (!release) {
throw new Error(`Could not find release for tag ${tag}${prerelease ? ' with prerelease' : ''}.`);
}
// Build regular expressions for all the target triple components
//
Expand All @@ -195,7 +225,7 @@ function run() {
let libcRegex = new RegExp("(gnu|glibc|musl)?"); // libc calling convention may not be specified
let extensionRegex = new RegExp(`${extMatchRegexForm}$`);
// Attempt to find the asset, with matches for arch, vendor, os, libc and extension as appropriate
let asset = getReleaseUrl.data.assets.find(obj => {
let asset = release.assets.find(obj => {
let normalized = obj.name.toLowerCase();
core.info(`checking for arch/vendor/os/glibc triple matches for (normalized) asset [${normalized}]`);
const nameIncluded = assetName ? normalized.includes(assetName) : true;
Expand Down Expand Up @@ -225,8 +255,8 @@ function run() {
return nameIncluded && osArchMatches && osMatches && vendorMatches && libcMatches && extensionMatches;
});
if (!asset) {
const found = getReleaseUrl.data.assets.map(f => f.name);
throw new Error(`Could not find a release for ${tag}. Found: ${found}`);
const found = release.assets.map(f => f.name);
throw new Error(`Could not find asset for ${tag}. Found: ${found}`);
}
const url = asset.url;
core.info(`Downloading ${assetName} from ${url}`);
Expand Down
65 changes: 50 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ async function run() {
let tag = core.getInput("tag");
tag = !tag ? "latest" : tag

let prerelease = core.getInput("prerelease") === "true"

const cacheEnabled = (core.getInput("cache") === "enable")
&& tag !== "latest"
&& tag !== "";
Expand Down Expand Up @@ -168,18 +170,51 @@ async function run() {
}
}

let getReleaseUrl;
if (tag === "latest") {
getReleaseUrl = await octokit.rest.repos.getLatestRelease({
owner: owner,
repo: repoName,
})
} else {
getReleaseUrl = await octokit.rest.repos.getReleaseByTag({
owner: owner,
repo: repoName,
tag: tag,
})
const getRelease = async () => {
if (tag === "latest") {
if (prerelease) {
let page = 1
const per_page = 30
while (true) {
const { data: releases } = await octokit.rest.repos.listReleases({
owner: owner,
repo: repoName,
per_page,
page
})
const release = releases.find(release => release.prerelease)
if (!!release) {
return release
}

if (releases.length < per_page) {
return undefined;
}

++page
}
} else {
const release = await octokit.rest.repos.getLatestRelease({
owner: owner,
repo: repoName,
})
return release.data
}
} else {
const release = await octokit.rest.repos.getReleaseByTag({
owner: owner,
repo: repoName,
tag: tag,
})
return release.data
}
}

let release = await getRelease()
if (!release) {
throw new Error(
`Could not find release for tag ${tag}${prerelease ? ' with prerelease' : ''}.`
)
}

// Build regular expressions for all the target triple components
Expand All @@ -198,7 +233,7 @@ async function run() {
let extensionRegex = new RegExp(`${extMatchRegexForm}$`)

// Attempt to find the asset, with matches for arch, vendor, os, libc and extension as appropriate
let asset = getReleaseUrl.data.assets.find(obj => {
let asset = release.assets.find(obj => {
let normalized = obj.name.toLowerCase()
core.info(`checking for arch/vendor/os/glibc triple matches for (normalized) asset [${normalized}]`)

Expand All @@ -219,9 +254,9 @@ async function run() {
})

if (!asset) {
const found = getReleaseUrl.data.assets.map(f => f.name)
const found = release.assets.map(f => f.name)
throw new Error(
`Could not find a release for ${tag}. Found: ${found}`
`Could not find asset for ${tag}. Found: ${found}`
)
}

Expand Down

0 comments on commit 97ca0c8

Please sign in to comment.