Skip to content

Commit

Permalink
Merge pull request #63 from Cyberbeni/macos-improvement
Browse files Browse the repository at this point in the history
only use architecture for uuid on macOS
  • Loading branch information
Cyberbeni authored Oct 9, 2020
2 parents e3547b5 + cf502d7 commit 9262b36
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 45 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ jobs:
- name: Ensure Built
run: |
make build
git status
[[ -z $(git status --porcelain) ]] || exit 1
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-18.04, ubuntu-20.04, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GitHub Action example:
```tsx
import { SwiftToolInstaller } from 'install-swift-tool'

SwiftToolInstaller.install(url, branch, version, useCache)
await SwiftToolInstaller.install(url, branch, version, useCache)
```

## How to contribute
Expand Down
30 changes: 14 additions & 16 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import * as os from 'os'
import * as semver from 'semver'

import { exec } from '../src/helpers'

const url = 'https://github.com/realm/SwiftLint'
// const url = 'https://github.com/realm/SwiftLint'

test('Get versions', async() => {
let versionsString = await exec('git', ['ls-remote', '--refs', '--tags', url])
let versions = versionsString.split('\n').map(function(value) {
return value.split('/').pop() ?? ''
})
let targetVersion = semver.maxSatisfying(versions, '^0')
console.log(versions)
console.log(targetVersion)
})

test('Get commit hash', async() => {
let resp = await exec('git', ['ls-remote', url, `HEAD`])
let commitHash = resp.substring(0,40)
console.log(resp)
console.log(commitHash)
test('Local test', async() => {
const osVersion = `${os.type()}-${os.release()}`
console.log(osVersion)
const swiftVersion = await exec('swift', ['-version'])
let additionalInfo = `${osVersion}-${swiftVersion}`
if (os.platform() == "darwin") {
let macVersion = await exec('sw_vers', ['-productVersion'])
if (semver.gte(macVersion, "10.14.4")) {
additionalInfo = `macos-${os.arch()}`
}
}
console.log(additionalInfo)
})
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions lib/helpers.js

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

2 changes: 1 addition & 1 deletion lib/main.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "install-swift-tool",
"version": "2.1.5",
"version": "2.1.6",
"description": "Install swift based tools inside a GitHub Action.",
"main": "lib/installer.js",
"repository": {
Expand Down
18 changes: 16 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as core from '@actions/core'
import { exec as _exec } from '@actions/exec'
import * as os from 'os'
import { v5 as _uuid } from 'uuid'
Expand All @@ -13,6 +14,19 @@ export async function exec(commandLine: string, args?: string[]): Promise<string
}

export async function getUuid(url: string, commitHash: string): Promise<string> {
const swiftVersion = await exec('swift', ['-version'])
return _uuid(`${url}-${commitHash}-${os.version}-${swiftVersion}`, '6050636b-7499-41d4-b9c6-756aff9856d0')
let additionalInfo: string
if (os.platform() == "darwin") {
additionalInfo = `macos-${os.arch()}`
} else {
let osVersion: string
if (os.version != undefined) {
osVersion = os.version()
} else {
core.warning('os.version undefined, using `uname -v` instead')
osVersion = await exec('uname', ['-v']) // os.version is somehow undefined on GitHub runner
}
const swiftVersion = await exec('swift', ['-version'])
additionalInfo = `${osVersion}-${os.arch()}-${swiftVersion}`
}
return _uuid(`${url}-${commitHash}-${additionalInfo}`, '6050636b-7499-41d4-b9c6-756aff9856d0')
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const useCache: boolean = core.getInput('use-cache') == 'true'
// Run

async function main(): Promise<void> {
SwiftToolInstaller.install(url, branch, version, useCache)
await SwiftToolInstaller.install(url, branch, version, useCache)
}

main().catch(error => { core.setFailed(error.message); })
7 changes: 3 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"outDir": "./lib",
"rootDir": "./src",
"esModuleInterop": true,
// Uncomment to generate new declaration, then remove unnecessary things by hand
// "declaration": true,
// "declarationDir": "./types",
"declaration": true,
"declarationDir": "./types",

// Lint:
"strict": true,
Expand All @@ -19,5 +18,5 @@
"noUnusedLocals": true,
"noUnusedParameters": true
},
"exclude": ["node_modules", "**/*.test.ts"]
"exclude": ["node_modules", "**/*.test.ts", "types"]
}
2 changes: 2 additions & 0 deletions types/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare function exec(commandLine: string, args?: string[]): Promise<string>;
export declare function getUuid(url: string, commitHash: string): Promise<string>;
20 changes: 20 additions & 0 deletions types/installer.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
export declare class SwiftToolInstaller {
readonly url: string;
branch: string;
readonly version: string;
readonly useCache: boolean;
private constructor();
resolveVersion(): Promise<void>;
uuid: string;
cacheKey: string;
workingDirectory: string;
productDirectory: string;
cacheDirectory: string;
updateDirectoryNames(newUuid: string): void;
createWorkingDirectory(): Promise<void>;
didRestore: boolean;
tryToRestore(): Promise<void>;
cloneGit(): Promise<void>;
buildTool(): Promise<void>;
tryToCache(): Promise<void>;
exportPath(): Promise<void>;
install(): Promise<void>;
static install(url: string, branch: string, version: string, useCache: boolean): Promise<void>;
}
1 change: 1 addition & 0 deletions types/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,9 @@
form-data "^3.0.0"

"@types/node@*", "@types/node@^14.11.2":
version "14.11.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.5.tgz#fecad41c041cae7f2404ad4b2d0742fdb628b305"
integrity sha512-jVFzDV6NTbrLMxm4xDSIW/gKnk8rQLF9wAzLWIOg+5nU6ACrIMndeBdXci0FGtqJbP9tQvm6V39eshc96TO2wQ==
version "14.11.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.8.tgz#fe2012f2355e4ce08bca44aeb3abbb21cf88d33f"
integrity sha512-KPcKqKm5UKDkaYPTuXSx8wEP7vE9GnuaXIZKijwRYcePpZFDVuy2a57LarFKiORbHOuTOOwYzxVxcUzsh2P2Pw==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
Expand Down Expand Up @@ -800,9 +800,9 @@
integrity sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==

"@types/yargs@^15.0.0":
version "15.0.7"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.7.tgz#dad50a7a234a35ef9460737a56024287a3de1d2b"
integrity sha512-Gf4u3EjaPNcC9cTu4/j2oN14nSVhr8PQ+BvBcBQHAhDZfl0bVIiLgvnRXv/dn58XhTm9UXvBpvJpDlwV65QxOA==
version "15.0.8"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.8.tgz#7644904cad7427eb704331ea9bf1ee5499b82e23"
integrity sha512-b0BYzFUzBpOhPjpl1wtAHU994jBeKF4TKVlT7ssFv44T617XNcPdRoG4AzHLVshLzlrF7i3lTelH7UbuNYV58Q==
dependencies:
"@types/yargs-parser" "*"

Expand Down Expand Up @@ -3695,14 +3695,14 @@ ts-jest@^26.4.0:
yargs-parser "20.x"

tslib@^1.10.0, tslib@^1.9.3:
version "1.13.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043"
integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==
version "1.14.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.0.tgz#d624983f3e2c5e0b55307c3dd6c86acd737622c6"
integrity sha512-+Zw5lu0D9tvBMjGP8LpvMb0u2WW2QV3y+D8mO6J+cNzCYIN4sVy43Bf9vl92nqFahutN0I8zHa7cc4vihIshnw==

tslib@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.1.tgz#410eb0d113e5b6356490eec749603725b021b43e"
integrity sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ==
version "2.0.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.0.2.tgz#462295631185db44b21b1ea3615b63cd1c038242"
integrity sha512-wAH28hcEKwna96/UacuWaVspVLkg4x1aDM9JlzqaQTOFczCktkVAb5fmXChgandR1EraDPs2w8P+ozM+oafwxg==

tunnel-agent@^0.6.0:
version "0.6.0"
Expand Down Expand Up @@ -3880,9 +3880,9 @@ whatwg-mimetype@^2.3.0:
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==

whatwg-url@^8.0.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.3.0.tgz#d1e11e565334486cdb280d3101b9c3fd1c867582"
integrity sha512-BQRf/ej5Rp3+n7k0grQXZj9a1cHtsp4lqj01p59xBWFKdezR8sO37XnpafwNqiFac/v2Il12EIMjX/Y4VZtT8Q==
version "8.4.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.4.0.tgz#50fb9615b05469591d2b2bd6dfaed2942ed72837"
integrity sha512-vwTUFf6V4zhcPkWp/4CQPr1TW9Ml6SF4lVyaIMBdJw5i6qUUJ1QWM4Z6YYVkfka0OUIzVo/0aNtGVGk256IKWw==
dependencies:
lodash.sortby "^4.7.0"
tr46 "^2.0.2"
Expand Down

0 comments on commit 9262b36

Please sign in to comment.