-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaction.yml
More file actions
100 lines (97 loc) · 4.24 KB
/
action.yml
File metadata and controls
100 lines (97 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: 'Start Coder Workspace'
description: 'Starts a Coder workspace and posts a status comment on a GitHub issue that updates with progress.'
inputs:
github-token:
description: 'GitHub token for posting the status comment'
required: false
default: ${{ github.token }}
github-issue-number:
description: 'GitHub issue number where the status comment will be posted (defaults to current issue context)'
required: false
github-username:
description: 'GitHub username of the user for whom the workspace is being started'
required: false
coder-username:
description: 'Coder username to override default user mapping (only set one of github-username or coder-username)'
required: false
coder-url:
description: 'Coder deployment URL'
required: true
coder-token:
description: 'API token for Coder'
required: true
template-name:
description: 'Name of the Coder template to use'
required: true
workspace-name:
description: 'Name for the new workspace (defaults to issue-{issue_number})'
required: false
parameters:
description: 'YAML-formatted parameters for the Coder workspace'
required: true
runs:
using: 'composite'
steps:
- name: Initial comment
id: initial-comment
uses: actions/github-script@v6
with:
github-token: ${{ inputs.github-token }}
script: |
const issueNumber = '${{ inputs.github-issue-number }}' ? Number('${{ inputs.github-issue-number }}') : context.issue.number;
if (!issueNumber) {
core.setFailed('No issue number provided and no issue context available');
return;
}
const serverUrl = '${{ github.server_url }}';
const runUrl = `${serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const comment = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `🔄 Starting a Coder workspace. You can track the progress [here](${runUrl}).`
});
core.setOutput('comment_id', comment.data.id);
core.setOutput('run_url', runUrl);
core.setOutput('repo_owner', context.repo.owner);
core.setOutput('repo_name', context.repo.repo);
core.setOutput('issue_number', issueNumber);
- name: Start workspace
shell: bash
env:
GITHUB_USERNAME: ${{ inputs.github-username }}
CODER_USERNAME: ${{ inputs.coder-username }}
CODER_URL: ${{ inputs.coder-url }}
CODER_TOKEN: ${{ inputs.coder-token }}
WORKSPACE_NAME: ${{ inputs.workspace-name || format('issue-{0}', steps.initial-comment.outputs.issue_number) }}
GITHUB_ISSUE_NUMBER: ${{ steps.initial-comment.outputs.issue_number }}
GITHUB_STATUS_COMMENT_ID: ${{ steps.initial-comment.outputs.comment_id }}
GITHUB_REPO_OWNER: ${{ steps.initial-comment.outputs.repo_owner }}
GITHUB_REPO_NAME: ${{ steps.initial-comment.outputs.repo_name }}
GITHUB_TOKEN: ${{ inputs.github-token }}
GITHUB_WORKFLOW_RUN_URL: ${{ steps.initial-comment.outputs.run_url }}
TEMPLATE_NAME: ${{ inputs.template-name }}
WORKSPACE_PARAMETERS: ${{ inputs.parameters }}
GITHUB_URL: ${{ github.api_url }}
run: |
node "${{ github.action_path }}/dist/index.js"
- name: Comment failure
if: always() && (failure() || cancelled())
uses: actions/github-script@v6
with:
github-token: ${{ inputs.github-token }}
script: |
const commentIdString = '${{ steps.initial-comment.outputs.comment_id }}';
if (!commentIdString) {
core.warning('No comment ID found, skipping status update');
return;
}
const commentId = Number(commentIdString);
const runUrl = '${{ steps.initial-comment.outputs.run_url }}';
const errorMsg = process.env["ERROR_MSG"];
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: "❌ " + (errorMsg ?? `Failed to start the workspace. Please check the [action logs](${runUrl}) for details.`)
});