cache based on branch name

pull/235/head
mdugdale 2021-04-03 02:14:24 +01:00
parent 15f18977f9
commit 99fd44f598
3 changed files with 16 additions and 14 deletions

14
dist/index.js vendored
View File

@ -222,9 +222,11 @@ const core = __importStar(__webpack_require__(42186));
const zlib = __importStar(__webpack_require__(78761)); const zlib = __importStar(__webpack_require__(78761));
class AWS { class AWS {
static runBuildJob(buildParameters, baseImage) { static runBuildJob(buildParameters, baseImage) {
var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const buildUid = nanoid_1.nanoid(); const buildUid = nanoid_1.nanoid();
const branchName = (_a = process.env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.split('/').reverse()[0];
core.info('starting part 1/4 (clone from github and restore cache)'); core.info('starting part 1/4 (clone from github and restore cache)');
yield this.run(buildUid, buildParameters.awsStackName, 'alpine/git', ['/bin/sh'], [ yield this.run(buildUid, buildParameters.awsStackName, 'alpine/git', ['/bin/sh'], [
'-c', '-c',
@ -236,11 +238,11 @@ class AWS {
git clone https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git ${buildUid}/repo; git clone https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git ${buildUid}/repo;
git clone https://${process.env.GITHUB_TOKEN}@github.com/game-ci/unity-builder.git ${buildUid}/builder; git clone https://${process.env.GITHUB_TOKEN}@github.com/game-ci/unity-builder.git ${buildUid}/builder;
if [ ! -d "cache" ]; then if [ ! -d "cache/${branchName}" ]; then
mkdir "cache" mkdir "cache/${branchName}"
fi fi
cd cache cd ./cache/${branchName}
ls ls
echo '' echo ''
@ -249,7 +251,7 @@ class AWS {
echo $latest echo $latest
if [ -f $latest ]; then if [ -f $latest ]; then
echo "Cache exists" echo "Cache exists"
unzip $latest ../${buildUid}/repo/Library/. unzip $latest ../../${buildUid}/repo/Library/.
else else
echo "Cache does not exist" echo "Cache does not exist"
fi fi
@ -369,7 +371,7 @@ class AWS {
` `
apk update; apk update;
apk add zip apk add zip
zip -r ./${buildUid}/repo/Library/* ./cache/lib-${buildUid}.zip zip -r ./${buildUid}/repo/Library/* ./cache/${branchName}/lib-${buildUid}.zip
zip -r ./${buildUid}/repo/build/* ./build-${buildUid}.zip zip -r ./${buildUid}/repo/build/* ./build-${buildUid}.zip
ls ls
`, `,
@ -389,7 +391,7 @@ class AWS {
'-c', '-c',
` `
aws s3 cp ./build-${buildUid}.zip s3://game-ci-storage/${buildUid}.zip aws s3 cp ./build-${buildUid}.zip s3://game-ci-storage/${buildUid}.zip
aws s3 cp ./cache/lib-${buildUid}.zip s3://game-ci-storage/lib-${buildUid}.zip aws s3 cp ./cache/${branchName}/lib-${buildUid}.zip s3://game-ci-storage/lib-${buildUid}.zip
rm -r ${buildUid} rm -r ${buildUid}
ls ls
`, `,

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,7 @@ class AWS {
static async runBuildJob(buildParameters, baseImage) { static async runBuildJob(buildParameters, baseImage) {
try { try {
const buildUid = nanoid(); const buildUid = nanoid();
const branchName = process.env.GITHUB_REF?.split('/').reverse()[0];
core.info('starting part 1/4 (clone from github and restore cache)'); core.info('starting part 1/4 (clone from github and restore cache)');
await this.run( await this.run(
buildUid, buildUid,
@ -25,11 +25,11 @@ class AWS {
git clone https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git ${buildUid}/repo; git clone https://${process.env.GITHUB_TOKEN}@github.com/${process.env.GITHUB_REPOSITORY}.git ${buildUid}/repo;
git clone https://${process.env.GITHUB_TOKEN}@github.com/game-ci/unity-builder.git ${buildUid}/builder; git clone https://${process.env.GITHUB_TOKEN}@github.com/game-ci/unity-builder.git ${buildUid}/builder;
if [ ! -d "cache" ]; then if [ ! -d "cache/${branchName}" ]; then
mkdir "cache" mkdir "cache/${branchName}"
fi fi
cd cache cd ./cache/${branchName}
ls ls
echo '' echo ''
@ -38,7 +38,7 @@ class AWS {
echo $latest echo $latest
if [ -f $latest ]; then if [ -f $latest ]; then
echo "Cache exists" echo "Cache exists"
unzip $latest ../${buildUid}/repo/Library/. unzip $latest ../../${buildUid}/repo/Library/.
else else
echo "Cache does not exist" echo "Cache does not exist"
fi fi
@ -179,7 +179,7 @@ class AWS {
` `
apk update; apk update;
apk add zip apk add zip
zip -r ./${buildUid}/repo/Library/* ./cache/lib-${buildUid}.zip zip -r ./${buildUid}/repo/Library/* ./cache/${branchName}/lib-${buildUid}.zip
zip -r ./${buildUid}/repo/build/* ./build-${buildUid}.zip zip -r ./${buildUid}/repo/build/* ./build-${buildUid}.zip
ls ls
`, `,
@ -210,7 +210,7 @@ class AWS {
'-c', '-c',
` `
aws s3 cp ./build-${buildUid}.zip s3://game-ci-storage/${buildUid}.zip aws s3 cp ./build-${buildUid}.zip s3://game-ci-storage/${buildUid}.zip
aws s3 cp ./cache/lib-${buildUid}.zip s3://game-ci-storage/lib-${buildUid}.zip aws s3 cp ./cache/${branchName}/lib-${buildUid}.zip s3://game-ci-storage/lib-${buildUid}.zip
rm -r ${buildUid} rm -r ${buildUid}
ls ls
`, `,