Skip to content

Commit

Permalink
Merge pull request #52 from Cyberbeni/handle-commit-changed
Browse files Browse the repository at this point in the history
recheck commit hash after cloning
  • Loading branch information
Cyberbeni authored Oct 5, 2020
2 parents 27b9a3d + ba1b784 commit 9e6152c
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 568 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Additional PR checks"

on: pull_request

jobs:
ensure-built:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Ensure Built
run: |
make build
[[ -z $(git status --porcelain) ]] || exit 1
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: |
make build
[[ -z $(git status --porcelain) ]] || exit 1
run: make build
- name: Run action without branch
uses: ./
with:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

30 changes: 29 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -9,8 +28,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.exec = void 0;
exports.getUuid = exports.exec = void 0;
const exec_1 = require("@actions/exec");
const os = __importStar(require("os"));
const uuid_1 = require("uuid");
function exec(commandLine, args) {
return __awaiter(this, void 0, void 0, function* () {
let output = '';
Expand All @@ -23,3 +44,10 @@ function exec(commandLine, args) {
});
}
exports.exec = exec;
function getUuid(url, commitHash) {
return __awaiter(this, void 0, void 0, function* () {
const swiftVersion = yield exec('swift', ['-version']);
return uuid_1.v5(`${url}-${commitHash}-${os.version}-${swiftVersion}`, '6050636b-7499-41d4-b9c6-756aff9856d0');
});
}
exports.getUuid = getUuid;
22 changes: 14 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const cache = __importStar(require("@actions/cache"));
const core = __importStar(require("@actions/core"));
const os = __importStar(require("os"));
const semver = __importStar(require("semver"));
const uuid_1 = require("uuid");
const helpers_1 = require("./helpers");
// Inputs
const url = core.getInput('url');
Expand Down Expand Up @@ -60,11 +59,16 @@ function resolve_version() {
}));
});
}
const homeDirectory = os.homedir();
let uuid = '';
let workingDirectory = '';
let productDirectory = '';
let cacheDirectory = '';
function updateDirectoryNames(newUuid) {
uuid = newUuid;
workingDirectory = `${os.homedir()}/install-swift-tool-${uuid}`;
productDirectory = `${workingDirectory}/.build/release`;
cacheDirectory = `${workingDirectory}/.build/*/release`;
}
function create_working_directory() {
return __awaiter(this, void 0, void 0, function* () {
yield core.group('Creating working directory', () => __awaiter(this, void 0, void 0, function* () {
Expand All @@ -76,11 +80,7 @@ function create_working_directory() {
commitHash = yield helpers_1.exec('git', ['ls-remote', url, `HEAD`]);
}
commitHash = commitHash.substring(0, 40);
const swiftVersion = yield helpers_1.exec('swift', ['-version']);
uuid = uuid_1.v5(`${url}-${commitHash}-${os.version}-${swiftVersion}`, '6050636b-7499-41d4-b9c6-756aff9856d0');
workingDirectory = `${homeDirectory}/install-swift-tool-${uuid}`;
productDirectory = `${workingDirectory}/.build/release`;
cacheDirectory = `${workingDirectory}/.build/*/release`;
updateDirectoryNames(yield helpers_1.getUuid(url, commitHash));
yield helpers_1.exec('mkdir', ['-p', workingDirectory]);
}));
});
Expand All @@ -105,7 +105,13 @@ function clone_git() {
else {
yield helpers_1.exec('git', ['clone', '--depth', '1', url, workingDirectory]);
}
yield helpers_1.exec('git', ['-C', workingDirectory, 'rev-parse', 'HEAD']);
const commitHash = yield helpers_1.exec('git', ['-C', workingDirectory, 'rev-parse', 'HEAD']);
const newUuid = yield helpers_1.getUuid(url, commitHash);
if (uuid != newUuid) {
const oldWorkingDirectory = workingDirectory;
updateDirectoryNames(newUuid);
yield helpers_1.exec('mv', [oldWorkingDirectory, workingDirectory]);
}
}));
});
}
Expand Down
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.1",
"version": "2.1.2",
"description": "Github action to install swift based tools",
"main": "lib/main.js",
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { exec as _exec } from '@actions/exec'
import * as os from 'os'
import { v5 as _uuid } from 'uuid'

export async function exec(commandLine: string, args?: string[]): Promise<string> {
let output: string = ''
Expand All @@ -9,3 +11,8 @@ export async function exec(commandLine: string, args?: string[]): Promise<string
})
return output
}

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')
}
26 changes: 15 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as cache from '@actions/cache'
import * as core from '@actions/core'
import * as os from 'os'
import * as semver from 'semver'
import { v5 as uuidv5 } from 'uuid'

import { exec } from './helpers'
import { exec, getUuid } from './helpers'

// Inputs

Expand Down Expand Up @@ -32,11 +31,16 @@ async function resolve_version(): Promise<void> {
})
}

const homeDirectory = os.homedir()
let uuid: string = ''
let workingDirectory = ''
let productDirectory = ''
let cacheDirectory = ''
function updateDirectoryNames(newUuid: string) {
uuid = newUuid
workingDirectory = `${os.homedir()}/install-swift-tool-${uuid}`
productDirectory = `${workingDirectory}/.build/release`
cacheDirectory = `${workingDirectory}/.build/*/release`
}
async function create_working_directory(): Promise<void> {
await core.group('Creating working directory', async () => {
let commitHash: string = ''
Expand All @@ -46,13 +50,7 @@ async function create_working_directory(): Promise<void> {
commitHash = await exec('git', ['ls-remote', url, `HEAD`])
}
commitHash = commitHash.substring(0,40)
const swiftVersion = await exec('swift', ['-version'])

uuid = uuidv5(`${url}-${commitHash}-${os.version}-${swiftVersion}`, '6050636b-7499-41d4-b9c6-756aff9856d0')
workingDirectory = `${homeDirectory}/install-swift-tool-${uuid}`
productDirectory = `${workingDirectory}/.build/release`
cacheDirectory = `${workingDirectory}/.build/*/release`

updateDirectoryNames(await getUuid(url, commitHash))
await exec('mkdir', ['-p', workingDirectory])
})
}
Expand All @@ -74,7 +72,13 @@ async function clone_git(): Promise<void> {
} else {
await exec('git', ['clone', '--depth', '1', url, workingDirectory])
}
await exec('git', ['-C', workingDirectory,'rev-parse', 'HEAD'])
const commitHash = await exec('git', ['-C', workingDirectory,'rev-parse', 'HEAD'])
const newUuid = await getUuid(url, commitHash)
if (uuid != newUuid) {
const oldWorkingDirectory = workingDirectory
updateDirectoryNames(newUuid)
await exec('mv', [oldWorkingDirectory, workingDirectory])
}
})
}

Expand Down
Loading

0 comments on commit 9e6152c

Please sign in to comment.