Skip to content

Commit

Permalink
add wait flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zzh8829 committed Oct 11, 2021
1 parent 58ae708 commit 660cd9e
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 10 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ inputs:
build:
description: "Trigger build or use latest image"
required: false
wait:
description: "Wait till the run finishes"
required: false
outputs:
link:
description: "Link to job execution"
Expand Down
49 changes: 45 additions & 4 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.

31 changes: 29 additions & 2 deletions src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export type ContainerStatus = {
};

export type CreateApiKeyInput = {
userID: Scalars['UUID'];
name: Scalars['String'];
};

Expand Down Expand Up @@ -2030,18 +2031,27 @@ export type Web3Challenge = {
nonce: Scalars['String'];
};

export type JobResultFragment = { __typename?: 'JobRun', id: any };
export type JobResultFragment = { __typename?: 'JobRun', id: any, state: JobRunState };

export type RunJobMutationVariables = Exact<{
input: RunJobInput;
}>;


export type RunJobMutation = { __typename?: 'Mutation', runJob: { __typename?: 'JobRun', id: any } };
export type RunJobMutation = { __typename?: 'Mutation', runJob: { __typename?: 'JobRun', id: any, state: JobRunState } };

export type GetJobQueryVariables = Exact<{
repo: Scalars['ID'];
job: Scalars['UUID'];
}>;


export type GetJobQuery = { __typename?: 'Query', currentUser: { __typename?: 'User', id: string, repo?: Maybe<{ __typename?: 'Repo', id: string, jobRun: { __typename?: 'JobRun', id: any, state: JobRunState } }> } };

export const JobResultFragmentDoc = gql`
fragment JobResult on JobRun {
id
state
}
`;
export const RunJobDocument = gql`
Expand All @@ -2052,6 +2062,20 @@ export const RunJobDocument = gql`
}
}
${JobResultFragmentDoc}`;
export const GetJobDocument = gql`
query GetJob($repo: ID!, $job: UUID!) {
currentUser {
id
repo(id: $repo) {
id
jobRun(id: $job) {
id
...JobResult
}
}
}
}
${JobResultFragmentDoc}`;

export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string) => Promise<T>;

Expand All @@ -2062,6 +2086,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
return {
RunJob(variables: RunJobMutationVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<RunJobMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<RunJobMutation>(RunJobDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'RunJob');
},
GetJob(variables: GetJobQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<GetJobQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<GetJobQuery>(GetJobDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'GetJob');
}
};
}
Expand Down
1 change: 1 addition & 0 deletions src/generated/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare module '*/mutation.gql' {
const defaultDocument: DocumentNode;
export const JobResult: DocumentNode;
export const RunJob: DocumentNode;
export const GetJob: DocumentNode;

export default defaultDocument;
}
Expand Down
35 changes: 32 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import {GraphQLClient} from 'graphql-request'
import {getSdk} from './generated/graphql'
import {getSdk, JobRunState} from './generated/graphql'

async function run(): Promise<void> {
try {
Expand All @@ -11,6 +11,7 @@ async function run(): Promise<void> {
const projectId = core.getInput('project_id')
const command = core.getInput('command')
const build = core.getBooleanInput('build')
const wait = core.getBooleanInput('wait')

const graphQLClient = new GraphQLClient(endpoint, {
headers: {
Expand All @@ -20,7 +21,7 @@ async function run(): Promise<void> {

const sdk = getSdk(graphQLClient)

const result = await sdk.RunJob({
const job = await sdk.RunJob({
input: {
id: projectId,
runCommand: command,
Expand All @@ -29,11 +30,39 @@ async function run(): Promise<void> {
})
core.info(`${projectId} job run triggered!`)

const link = `https://zeet.co/repo/${projectId}/jobs/${result?.runJob?.id}`
const link = `https://zeet.co/repo/${projectId}/jobs/${job?.runJob?.id}`

core.info(`Zeet Dashboard: ${link}`)
core.setOutput('link', link)

if (wait) {
let done = false
while (!done) {
const result = await sdk.GetJob({
repo: projectId,
job: job?.runJob?.id
})

if (
result.currentUser?.repo?.jobRun?.state === JobRunState.JobRunRunning
) {
core.info('job executing...')
} else if (
result.currentUser?.repo?.jobRun?.state ===
JobRunState.JobRunSucceeded
) {
core.info('job succeeded')
done = true
} else if (
result.currentUser?.repo?.jobRun?.state === JobRunState.JobRunFailed
) {
core.info('job failed, check Zeet dashboard for more info')
core.setFailed('job failed, check Zeet dashboard for more info')
done = true
}
}
}

core.debug(new Date().toTimeString())
} catch (error) {
if (error instanceof Error) {
Expand Down
14 changes: 14 additions & 0 deletions src/mutation.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fragment JobResult on JobRun {
id
state
}

mutation RunJob($input: RunJobInput!) {
Expand All @@ -8,3 +9,16 @@ mutation RunJob($input: RunJobInput!) {
...JobResult
}
}

query GetJob($repo: ID!, $job: UUID!) {
currentUser {
id
repo(id: $repo) {
id
jobRun(id: $job) {
id
...JobResult
}
}
}
}

0 comments on commit 660cd9e

Please sign in to comment.