-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Extract each step to seperate file
Also update documentation
- Loading branch information
Showing
11 changed files
with
359 additions
and
233 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
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
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 |
---|---|---|
@@ -1,20 +1,31 @@ | ||
# setup-processing | ||
|
||
[![CI with Linux](https://github.com/ifP1/setup-processing/workflows/CI%20with%20Linux/badge.svg)](https://github.com/ifP1/setup-processing/actions?query=workflow%3A%22CI+with+Linux%22) | ||
[![CI with Windows](https://github.com/ifP1/setup-processing/workflows/CI%20with%20Windows/badge.svg)](https://github.com/ifP1/setup-processing/actions?query=workflow%3A%22CI+with+Windows%22) | ||
[![CI with MacOS](https://github.com/ifP1/setup-processing/workflows/CI%20with%20MacOS/badge.svg)](https://github.com/ifP1/setup-processing/actions?query=workflow%3A%22CI+with+MacOS%22) | ||
[![GitHub issues](https://img.shields.io/github/issues/ifP1/setup-processing)](https://github.com/ifP1/setup-processing/issues) | ||
[![CI with Linux](https://github.com/ifP1/setup-processing/workflows/CI%20with%20Linux/badge.svg)](https://github.com/pr1metine/setup-processing/actions?query=workflow%3A%22CI+with+Linux%22) | ||
[![CI with Windows](https://github.com/ifP1/setup-processing/workflows/CI%20with%20Windows/badge.svg)](https://github.com/pr1metine/setup-processing/actions?query=workflow%3A%22CI+with+Windows%22) | ||
[![CI with MacOS](https://github.com/ifP1/setup-processing/workflows/CI%20with%20MacOS/badge.svg)](https://github.com/pr1metine/setup-processing/actions?query=workflow%3A%22CI+with+MacOS%22) | ||
[![GitHub issues](https://img.shields.io/github/issues/ifP1/setup-processing)](https://github.com/pr1metine/setup-processing/issues) | ||
|
||
Sets up the Processing SDK. Will try to fetch https://processing.org/download/processing-${version}-${platform-filetype} | ||
Sets up the Processing SDK. Given a tag name and a release asset name, `setup-processing` will try to download a release asset from [Processing 4](https://github.com/processing/processing4/releases) or [Processing](https://github.com/processing/processing/releases). | ||
|
||
## Note | ||
|
||
- If no tag name `tag` is provided, the latest release will be used. | ||
- If no asset name `asset-name` is provided, this action will try to choose the right asset based on the Action Runner's OS and CPU architecture. | ||
|
||
## Code | ||
|
||
```yaml | ||
- name: Setup Processing | ||
uses: pr1metine/setup-processing@v1.1.1 | ||
uses: pr1metine/setup-processing@v2.0.0 | ||
with: | ||
# Version of Processing, e.g. 3.5.4 | ||
version: # default is 3.5.4 | ||
# e.g. 'windows64.zip', 'windows32.zip', 'linux64.tgz' | ||
platform-filetype: # optional, default is linux64.tgz | ||
# Tag of Processing GitHub Release, e.g. processing-1292-4.2 | ||
# See https://github.com/processing/processing4/releases and | ||
# https://github.com/processing/processing4/releases | ||
tag: # optional, will use latest release by default | ||
# Name of a Processing GitHub Release Asset, e.g. processing-4.2-linux-arm64.tgz | ||
asset-name: # optional, will infer based on Runner by default | ||
``` | ||
## Development | ||
[This file](src/index.ts) serves as this Action's entry point. Use [act](https://github.com/nektos/act) to test this GitHub Action locally before pushing. |
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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import * as core from "@actions/core"; | ||
import * as tc from "@actions/tool-cache"; | ||
import { ArchiveType, ReleaseAsset } from "./types"; | ||
|
||
/** | ||
* Download a specified asset from a GitHub Release. | ||
* | ||
* If no assetName is given, `setup-processing` tries to infer the | ||
* assetName. It does so based on the OS and CPU architecture of | ||
* the GitHub runner. | ||
* | ||
* @param assets Available assets for a Processing release | ||
* @param assetName Name of the specified asset to be downloaded | ||
* @returns Path to extracted asset | ||
*/ | ||
async function downloadAsset( | ||
assets: ReleaseAsset[], | ||
assetName?: string | ||
): Promise<string> { | ||
let asset = getAssetByName(assets, assetName); | ||
if (asset === undefined) { | ||
throw new Error( | ||
`The given archive name does not exist: ${ | ||
assetName ?? "(Infered, please open an issue for this)" | ||
} | ||
Available choices were: ${JSON.stringify( | ||
assets.map((asset) => asset.name) | ||
)} | ||
` | ||
); | ||
} | ||
core.info(`Downloading release asset "${asset.name}"`); | ||
|
||
let path = await extractTool( | ||
await tc.downloadTool(asset.url), | ||
asset.content_type | ||
); | ||
|
||
return path; | ||
} | ||
|
||
function getAssetByName( | ||
assets: ReleaseAsset[], | ||
assetName?: string | ||
): ReleaseAsset | undefined { | ||
if (assetName === undefined) { | ||
core.info( | ||
`Infering correct asset file name (os=${process.platform}, arch=${process.arch})...` | ||
); | ||
let matchers = getMatchers(process.platform, process.arch); | ||
return assets.find((asset) => | ||
matchers.every((matcher) => asset.name.match(matcher) !== null) | ||
); | ||
} | ||
|
||
return assets.find((asset) => asset.name === assetName); | ||
} | ||
function getMatchers(os: NodeJS.Platform, arch: NodeJS.Architecture): RegExp[] { | ||
let out = new Array<RegExp>(); | ||
switch (os) { | ||
case "win32": | ||
out.push(/.*windows.*/); | ||
break; | ||
case "linux": | ||
out.push(/.*linux.*/); | ||
break; | ||
case "darwin": | ||
out.push(/.*macos.*/); | ||
break; | ||
default: | ||
throw new Error(`Unsupported platform ${os}. Please open an issue`); | ||
} | ||
|
||
switch (arch) { | ||
case "arm": | ||
out.push(/.*(arm32|armv6hf).*/); | ||
break; | ||
case "arm64": | ||
out.push(/.*(arm64|aarch64).*/); | ||
break; | ||
case "x64": | ||
out.push(/.*(x64|linux64|windows64|macosx).*/); | ||
break; | ||
// Apparently no x86 32 bit | ||
default: | ||
throw new Error(`Unsupported architecture ${arch}. Please open an issue`); | ||
} | ||
|
||
return out; | ||
} | ||
function extractTool(path: string, type: ArchiveType): Promise<string> { | ||
switch (type) { | ||
case "application/zip": | ||
return tc.extractZip(path, "extracted-processing"); | ||
case "application/octet-stream": | ||
core.warning( | ||
`Asset type of ${path} is "application/octet-stream". Assumed to be gzip` | ||
); | ||
case "application/gzip": | ||
return tc.extractTar(path, "extracted-processing"); | ||
} | ||
} | ||
|
||
export default downloadAsset; |
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,93 @@ | ||
import * as core from "@actions/core"; | ||
import { Octokit, RestEndpointMethodTypes } from "@octokit/rest"; | ||
|
||
import { ArchiveType, Release, Repository } from "./types"; | ||
|
||
let OCTOKIT = new Octokit(); | ||
|
||
/** | ||
* Retrieves a release with the specified tag. | ||
* | ||
* If no tag is specified, the latest will be returned. This function will search for | ||
* the given tag inside the given repositories `repos`. If the given tag occurs in | ||
* multiple repositories, the release from the left most repo of `repos` will be | ||
* returned. | ||
* | ||
* @param repos Repositories to look for a Processing release | ||
* @param tag The tag of the desired release | ||
* @returns The desired release | ||
*/ | ||
async function getReleaseByTag( | ||
repos: Repository[], | ||
tag?: string | ||
): Promise<Release> { | ||
if (repos.length < 1) { | ||
throw new Error( | ||
`No Processing repos specified in which to look for the specified tag` | ||
); | ||
} | ||
|
||
let releases = await Promise.allSettled( | ||
repos.map((repo) => | ||
tag !== undefined | ||
? OCTOKIT.rest.repos.getReleaseByTag({ | ||
...repo, | ||
tag: tag, | ||
}) | ||
: OCTOKIT.rest.repos.getLatestRelease(repo) | ||
) | ||
).then((results) => | ||
results.filter(isFulfilled).map((result) => result.value) | ||
); | ||
|
||
let successfullyRetrievedReleases = releases.filter( | ||
(release) => release.status >= 200 && release.status < 300 | ||
); | ||
|
||
if (successfullyRetrievedReleases.length < 1) { | ||
throw new Error( | ||
`Could not find a Processing release for the following tag: ${JSON.stringify( | ||
tag | ||
)}` | ||
); | ||
} | ||
|
||
let release = successfullyRetrievedReleases[0].data; | ||
|
||
core.debug(`Pruning asset descriptions: ${JSON.stringify(release.assets)}`); | ||
let out = { | ||
tag: release.tag_name, | ||
assets: release.assets.map((asset) => { | ||
return { | ||
name: asset.name, | ||
url: asset.browser_download_url, | ||
content_type: getArchiveType(asset.content_type), | ||
}; | ||
}), | ||
}; | ||
|
||
return out; | ||
} | ||
|
||
const isFulfilled = <T>( | ||
input: PromiseSettledResult<T> | ||
): input is PromiseFulfilledResult<T> => input.status === "fulfilled"; | ||
|
||
function getArchiveType(content_type: string): ArchiveType { | ||
if ( | ||
content_type !== "application/zip" && | ||
content_type !== "application/gzip" && | ||
content_type !== "application/octet-stream" | ||
) { | ||
throw new Error( | ||
`Unsupported archive type: ${content_type}. Please file an issue` | ||
); | ||
} | ||
|
||
if (content_type === "application/octet-stream") { | ||
} | ||
|
||
return <ArchiveType>content_type; | ||
} | ||
|
||
export default getReleaseByTag; |
Oops, something went wrong.