chore: disable github action

Will implement with new version of github later on
This commit is contained in:
Kyle Fang
2019-09-22 15:28:33 +08:00
parent b867f43086
commit 2c3b11fb99
9 changed files with 9 additions and 279 deletions

52
.github/main.workflow vendored
View File

@@ -1,52 +0,0 @@
workflow "Test" {
on = "push"
resolves = ["TypeCheck and TSLint"]
}
action "TypeCheck and TSLint" {
uses = "./.github/yarn"
args = "ci"
}
workflow "Deploy services on PR merge" {
on = "push"
resolves = ["Deploy Services"]
}
action "Filter Master Branch" {
uses = "actions/bin/filter@master"
args = "branch master"
}
action "Deploy Services" {
needs = ["Filter Master Branch"]
uses = "./.github/yarn"
args = "deploy:dev"
secrets = [
"FIREBASE_TOKEN"
]
}
workflow "Deploy app on Release" {
on = "release"
resolves = ["Deploy Apps"]
}
action "On Release Published" {
uses = "actions/bin/filter@master"
args = "action published"
}
action "Deploy Apps" {
needs = ["On Release Published"]
uses = "./.github/yarn"
args = "workspace @mercy/scripts deploy:ci"
secrets = [
"FIREBASE_TOKEN",
"MAC_PASSWORD",
"MAC_USERNAME",
"MAC_HOST",
"MAC_PORT",
"MAC_PROJECT_PATH"
]
}

View File

@@ -1,19 +0,0 @@
FROM node:10-alpine
LABEL "com.github.actions.name"="Yarn with Install"
LABEL "com.github.actions.description"="yarn install then yarn"
LABEL "com.github.actions.icon"="mic"
LABEL "com.github.actions.color"="purple"
ENV YARN_VERSION 1.15.2
RUN apk add --update git curl \
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/ \
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarn /usr/local/bin/yarn \
&& ln -snf /opt/yarn-v$YARN_VERSION/bin/yarnpkg /usr/local/bin/yarnpkg \
&& rm yarn-v$YARN_VERSION.tar.gz
COPY "entrypoint.sh" "/entrypoint.sh"
ENTRYPOINT ["/entrypoint.sh"]
CMD ["help"]

View File

@@ -1,14 +0,0 @@
#!/bin/sh -l
(
set -e
sh -c "yarn install"
sh -c "yarn $*"
)
errorCode=$?
if [ $errorCode -ne 0 ]; then
echo "We have an error"
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Error in Action:\n*action*:$GITHUB_WORKFLOW - $GITHUB_ACTION\n*by*:$GITHUB_ACTOR\n*in*:$GITHUB_REF\"}" \
PHARAH_SLACK_URL
exit $errorCode
fi

View File

@@ -1,36 +0,0 @@
#!./node_modules/.bin/ts-node
import * as fs from "fs";
import * as path from "path";
import {
isInGithubAction,
getRemoteOptions,
getRelease
} from "./utils/githubAction";
import { deployRemotely, deploy } from "./utils/release";
import chalk from "chalk";
(async () => {
if (isInGithubAction()) {
await deployRemotely(getRemoteOptions(), getRelease());
return;
}
if (fs.existsSync(path.resolve(__dirname, "./deploy.json"))) {
await deploy();
return;
}
console.log(`
./deploy.ts
Usage:
you need a ${chalk.bold("deploy.json")} that contains following
{
"prerelease": false,
"tag_name": "1.1.1",
"body": "release note"
}
`);
})();

View File

@@ -5,8 +5,7 @@
"scripts": {
"lint": "tslint -p .",
"build": "tsc",
"ci": "yarn lint && yarn build",
"deploy:ci": "ts-node ./deploy.ts"
"ci": "yarn lint && yarn build"
},
"dependencies": {
"@types/fs-extra": "^7.0.0",
@@ -18,7 +17,6 @@
"meow": "^5.0.0",
"ora": "^3.1.0",
"replace-in-file": "^3.4.4",
"ssh-exec": "^2.0.0",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0",

View File

@@ -1,19 +0,0 @@
declare module "ssh-exec" {
import { Readable } from "node";
export interface SshExecOptions {
user: string;
password: string;
host: string;
port: string;
}
declare function ExecRemoteFunction(
command: string,
options: SshExecOptions,
callback: (
error: Error | undefined,
stdout: string | undefined,
stderr: string | undefined
) => void
): Readable;
export = ExecRemoteFunction;
}

View File

@@ -1,52 +0,0 @@
import * as process from "process";
import * as fs from "fs";
export const isInGithubAction = () => {
return process.env.GITHUB_EVENT_PATH != null;
};
export interface GithubRelease {
body: string;
tag_name: string;
prerelease: boolean;
}
export const getRelease = (): {
body: string;
tag_name: string;
prerelease: boolean;
} => {
if (!process.env.GITHUB_EVENT_PATH) {
throw new Error("GITHUB_EVENT_PATH not exist");
}
const event = JSON.parse(
fs.readFileSync(process.env.GITHUB_EVENT_PATH, {
encoding: "utf-8"
})
);
const { body, tag_name, prerelease } = event.release;
return {
body,
tag_name,
prerelease
};
};
export interface RemoteOption {
user: string;
password: string;
host: string;
port: string;
cwd: string;
}
export const getRemoteOptions = (): RemoteOption =>
({
cwd: process.env.MAC_PROJECT_PATH,
user: process.env.MAC_USERNAME,
password: process.env.MAC_PASSWORD,
host: process.env.MAC_HOST,
port: process.env.MAC_PORT
} as any);

View File

@@ -1,54 +0,0 @@
import { GithubRelease, RemoteOption } from "./githubAction";
import { run, runRemotely } from "./run";
import * as fs from "fs";
import * as path from "path";
export const deployRemotely = async (
options: RemoteOption,
release: GithubRelease
) => {
const command = `
cd ${options.cwd}
security unlock-keychain -p ${options.password} login.keychain
git reset --hard HEAD
git clean -fd
git fetch --prune --prune-tags
git checkout ${release.tag_name}
yarn install
echo ${JSON.stringify(JSON.stringify(release, null, 2))
.replace(/\\r/g, "\\\\r")
.replace(/\\n/g, "\\\\n")} > ./scripts/deploy.json
./scripts/deploy.ts
`;
console.log(command);
await runRemotely(command, options);
};
const getLocalReleaseOptions = (): GithubRelease => {
return JSON.parse(
fs.readFileSync(path.resolve(__dirname, "../deploy.json"), {
encoding: "utf-8"
})
);
};
export const deploy = async () => {
const release = getLocalReleaseOptions();
const command = `
pushd ../app/ios
bundle install
bundle exec pod install --repo-update
bundle exec fastlane ${release.prerelease ? "internal" : "beta"} tag:${
release.tag_name
} changelog:${JSON.stringify(release.body)} > deploy.log
popd
pushd ../app/android
bundle install
bundle exec fastlane ${release.prerelease ? "internal" : "beta"} tag:${
release.tag_name
} changelog:${JSON.stringify(release.body)} > deploy.log
popd
`;
await run(command);
};

View File

@@ -1,40 +1,18 @@
import { exec } from "child_process";
import execRemote = require("ssh-exec");
import * as path from "path";
export const run = (command: string) =>
new Promise((ful, rej) => {
const { stdout } = exec(
command,
{ cwd: path.resolve(__dirname, "..") },
(error, _, stderr) => {
if (stderr) {
console.log(stderr);
}
if (error) {
rej(error);
} else {
ful();
}
}
);
if (stdout) {
stdout.pipe(process.stdout);
}
});
export const runRemotely = (
command: string,
options: execRemote.SshExecOptions
) =>
new Promise((ful, rej) => {
execRemote(command, options, (error, _, stderr) => {
if (error) {
const { stdout } = exec(command, (error, _, stderr) => {
if (stderr) {
console.log(stderr);
console.log(error.message);
}
if (error) {
rej(error);
} else {
ful();
}
}).pipe(process.stdout);
});
if (stdout) {
stdout.pipe(process.stdout);
}
});