Skip to content

Commit

Permalink
feat: support dev version spec with commit (#142)
Browse files Browse the repository at this point in the history
* ci: test coverage 0.11 and dev tag

Signed-off-by: tison <wander4096@gmail.com>

* support pin commit ver

Signed-off-by: tison <wander4096@gmail.com>

* ncc

Signed-off-by: tison <wander4096@gmail.com>

* run all

Signed-off-by: tison <wander4096@gmail.com>

* fix master

Signed-off-by: tison <wander4096@gmail.com>

* ncc

Signed-off-by: tison <wander4096@gmail.com>

* fix ext

Signed-off-by: tison <wander4096@gmail.com>

---------

Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Dec 1, 2023
1 parent 49a6f91 commit 5d386f4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
strategy:
fail-fast: false
matrix:
zig: [ 0.10.0, 0.9.1, 0.8.1, master ]
zig: [ 0.12.0-dev.1710+2bffd8101, 0.11.0, 0.10.0, master ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
runs-on: ${{ matrix.os }}
name: Zig ${{ matrix.zig }} on ${{ matrix.os }}
Expand Down
58 changes: 43 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

68 changes: 49 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,27 @@ interface DistroData {
size: string
}

async function resolveTargetPlatform(): Promise<string> {
const platformPattern = /(?<arch>\w+)-(?<os>\w+)/

async function resolveArchPlatform(): Promise<{
arch: string
platform: string
}> {
const targetPlatform: string = core.getInput('target-platform')
if (targetPlatform && targetPlatform.length > 0) {
return targetPlatform
const matches = platformPattern.exec(targetPlatform)
if (matches && matches.groups) {
return {
arch: matches.groups.arch,
platform: matches.groups.os
}
} else {
throw new Error(`Unparsed target-platform: ${targetPlatform}`)
}
}

const platform = process.platform
let resolvedPlatform
let resolvedPlatform: string
switch (platform) {
case 'darwin':
resolvedPlatform = 'macos'
Expand All @@ -58,7 +71,7 @@ async function resolveTargetPlatform(): Promise<string> {
}

const arch = process.arch
let resolvedArch
let resolvedArch: string
switch (arch) {
case 'arm64':
resolvedArch = 'aarch64'
Expand All @@ -76,7 +89,10 @@ async function resolveTargetPlatform(): Promise<string> {
throw new Error(`Unsupported arch: ${arch}`)
}

return `${resolvedArch}-${resolvedPlatform}`
return {
arch: resolvedArch,
platform: resolvedPlatform
}
}

async function downloadZigDistrosMetadata(): Promise<any> {

Check warning on line 98 in src/main.ts

View workflow job for this annotation

GitHub Actions / Build actions

Unexpected any. Specify a different type

Check warning on line 98 in src/main.ts

View workflow job for this annotation

GitHub Actions / main

Unexpected any. Specify a different type
Expand All @@ -89,31 +105,45 @@ async function main(): Promise<void> {
const zigVersion: string = core.getInput('zig-version')
const zigDistros = await downloadZigDistrosMetadata()
const availableVersions = Object.keys(zigDistros)
if (!availableVersions.includes(zigVersion)) {
throw new Error(`Unsupported version: ${zigVersion}`)
}

const zigVersionedDistro = (zigDistros as Record<string, any>)[zigVersion]
const versionSpec = zigVersion !== 'master' ? zigVersion : zigVersionedDistro['version']
core.info(`Using version ${versionSpec}...`)
const {arch, platform} = await resolveArchPlatform()
const targetPlatform = `${arch}-${platform}`
core.info(`Targeting to platform ${targetPlatform}...`)

let versionSpec: string
let tarballLink: string

const targetPlatform: string = await resolveTargetPlatform()
const availablePlatform = Object.keys(zigVersionedDistro)
if (!availablePlatform.includes(targetPlatform)) {
throw new Error(`Unsupported platform: ${targetPlatform}`)
if (!availableVersions.includes(zigVersion) && zigVersion !== 'master') {
versionSpec = zigVersion
let extension: string
if (platform === 'windows') {
extension = 'zip'
} else {
extension = 'tar.xz'
}
tarballLink = `https://ziglang.org/builds/zig-${platform}-${arch}-${versionSpec}.${extension}`
core.info(`Using version ${versionSpec} with link ${tarballLink}`)
} else {
const zigVersionedDistro = (zigDistros as Record<string, any>)[zigVersion]

Check warning on line 127 in src/main.ts

View workflow job for this annotation

GitHub Actions / Build actions

Unexpected any. Specify a different type

Check warning on line 127 in src/main.ts

View workflow job for this annotation

GitHub Actions / main

Unexpected any. Specify a different type
versionSpec = zigVersion !== 'master' ? zigVersion : zigVersionedDistro['version']
core.info(`Using version ${versionSpec}...`)
const availablePlatform = Object.keys(zigVersionedDistro)
if (!availablePlatform.includes(targetPlatform)) {
throw new Error(`Unsupported platform: ${targetPlatform}`)
}
const zigDistro = (zigVersionedDistro as Record<string, DistroData>)[targetPlatform]
tarballLink = zigDistro.tarball
core.info(`Using link ${tarballLink}`)
}
core.info(`Targeting to platform ${targetPlatform}...`)

const toolPath = cache.find('zig', versionSpec, targetPlatform)
if (toolPath) {
core.info(`Cache hit ${toolPath}`)
core.addPath(toolPath)
return
}

core.info(`Cache miss. Downloading...`)
const zigDistro = (zigVersionedDistro as Record<string, DistroData>)[targetPlatform]
const tarballLink = zigDistro.tarball

const tarballPath = await cache.downloadTool(tarballLink)
let extractedPath: string
if (tarballLink.endsWith('tar.xz')) {
Expand Down

0 comments on commit 5d386f4

Please sign in to comment.