@@ -10,7 +10,10 @@ inputs:
10
10
required : true
11
11
github-username :
12
12
description : ' GitHub username of the user for whom the workspace is being started'
13
- required : true
13
+ required : false
14
+ coder-username :
15
+ description : ' Coder username'
16
+ required : false
14
17
coder-url :
15
18
description : ' Coder URL'
16
19
required : true
@@ -37,145 +40,45 @@ runs:
37
40
script : |
38
41
const issueNumber = Number('${{ inputs.github-issue-number }}');
39
42
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
40
- await github.rest.issues.createComment({
43
+ const comment = await github.rest.issues.createComment({
41
44
owner: context.repo.owner,
42
45
repo: context.repo.repo,
43
46
issue_number: issueNumber,
44
47
body: `Starting a Coder workspace. You can track the progress [here](${runUrl}).`
45
48
});
49
+ core.setOutput('comment_id', comment.data.id);
50
+ core.setOutput('run_url', runUrl);
46
51
47
- - name : Check if Coder CLI is available
48
- id : check-coder
52
+ - name : Start workspace
49
53
shell : bash
50
- run : |
51
- if command -v coder &> /dev/null; then
52
- echo "Coder CLI is already installed"
53
- echo "coder_installed=true" >> $GITHUB_OUTPUT
54
- else
55
- echo "Coder CLI is not installed"
56
- echo "coder_installed=false" >> $GITHUB_OUTPUT
57
- fi
58
-
59
- - name : Install Coder CLI
60
- if : steps.check-coder.outputs.coder_installed != 'true'
61
- uses : coder/setup-action@4a607a8113d4e676e2d7c34caa20a814bc88bfda
62
- with :
63
- access_url : ${{ inputs.coder-url }}
64
- coder_session_token : ${{ inputs.coder-token }}
65
-
66
- - name : Get GitHub username and id
67
- id : github-user
68
- uses : actions/github-script@v6
69
54
env :
70
55
GITHUB_USERNAME : ${{ inputs.github-username }}
71
- with :
72
- github-token : ${{ inputs.github-token }}
73
- script : |
74
- const githubUsername = (process.env.GITHUB_USERNAME ?? '').trim();
75
- const githubUser = await github.rest.users.getByUsername({
76
- username: githubUsername
77
- });
78
- core.setOutput('github_username', githubUsername);
79
- core.setOutput('github_user_id', githubUser.data.id);
80
-
81
- - name : Get Coder Users List
82
- id : coder-user-list
83
- shell : bash
84
- run : |
85
- {
86
- echo "cmd_output<<EOF"
87
- coder users list \
88
- --url '${{ inputs.coder-url }}' \
89
- --token '${{ inputs.coder-token }}' \
90
- --github-user-id '${{ steps.github-user.outputs.github_user_id }}' \
91
- --column username
92
- echo "EOF"
93
- } >> $GITHUB_OUTPUT
94
-
95
- - name : Get Coder User
96
- id : coder-user
97
- uses : actions/github-script@v6
98
- env :
99
- CODER_USERS_LIST_OUTPUT : ${{ steps.coder-user-list.outputs.cmd_output }}
100
- with :
101
- github-token : ${{ inputs.github-token }}
102
- script : |
103
- const listOutput = (process.env.CODER_USERS_LIST_OUTPUT ?? '').trim();
104
-
105
- const lines = listOutput.split('\n')
106
- if (lines.length < 2) {
107
- console.log('No Coder username mapping found for GitHub user')
108
- return
109
- }
110
- if (lines.length > 2) {
111
- console.log('Multiple Coder usernames found for GitHub user. Using the first one.')
112
- }
113
- const coderUsername = lines[1].trim()
114
- core.setOutput('coder_username', coderUsername)
115
- core.setOutput('has_mapping', String(coderUsername.length > 0))
116
-
117
- - name : No user mapping comment
118
- if : steps.coder-user.outputs.has_mapping != 'true'
119
- uses : actions/github-script@v6
120
- with :
121
- github-token : ${{ inputs.github-token }}
122
- script : |
123
- const issueNumber = Number('${{ inputs.github-issue-number }}');
124
- const githubUsername = '${{ steps.github-user.outputs.github_username }}';
125
- const externalAuthPage = '${{ inputs.coder-url }}/settings/external-auth';
126
- const errMsg = `No matching Coder user found for GitHub user \`${githubUsername}\`. Please connect your GitHub account with Coder: ${externalAuthPage}`;
127
- require('fs').appendFileSync(process.env["GITHUB_ENV"], `ERROR_MSG=${errMsg}\n`);
128
- core.setFailed(errMsg)
129
-
130
- - name : Create parameters file
131
- shell : bash
132
- run : |
133
- mkdir -p /tmp/coder
134
- echo '${{ inputs.parameters }}' > /tmp/coder/parameters.yml
135
- echo "PARAMETERS_FILE=/tmp/coder/parameters.yml" >> $GITHUB_ENV
136
-
137
- - name : Start Coder workspace
138
- id : start-workspace
139
- shell : bash
140
- env :
56
+ CODER_USERNAME : ${{ inputs.coder-username }}
141
57
CODER_URL : ${{ inputs.coder-url }}
142
58
CODER_TOKEN : ${{ inputs.coder-token }}
143
- TEMPLATE_NAME : ${{ inputs.template-name }}
144
59
WORKSPACE_NAME : ${{ inputs.workspace-name }}
60
+ GITHUB_STATUS_COMMENT_ID : ${{ steps.initial-comment.outputs.comment_id }}
61
+ GITHUB_REPO_OWNER : ${{ context.repo.owner }}
62
+ GITHUB_REPO_NAME : ${{ context.repo.repo }}
63
+ GITHUB_TOKEN : ${{ inputs.github-token }}
64
+ GITHUB_WORKFLOW_RUN_URL : ${{ steps.initial-comment.outputs.run_url }}
65
+ TEMPLATE_NAME : ${{ inputs.template-name }}
66
+ WORKSPACE_PARAMETERS : ${{ inputs.parameters }}
145
67
run : |
146
- set -o pipefail
147
- set -o errexit
148
-
149
- bash -c "yes '' || true" | coder --url '${{ inputs.coder-url }}' --token '${{ inputs.coder-token }}' create --yes --template '${{ inputs.template-name }}' '${{ inputs.workspace-name }}' --rich-parameter-file $PARAMETERS_FILE
150
- WORKSPACE_URL="${{ inputs.coder-url }}/${{ steps.coder-user.outputs.coder_username }}/${{ inputs.workspace-name }}"
151
- echo "workspace_url=${WORKSPACE_URL}" >> $GITHUB_OUTPUT
152
-
153
- - name : Comment success
154
- uses : actions/github-script@v6
155
- with :
156
- github-token : ${{ inputs.github-token }}
157
- script : |
158
- const issueNumber = Number('${{ inputs.github-issue-number }}');
159
- const workspaceUrl = '${{ steps.start-workspace.outputs.workspace_url }}';
160
- await github.rest.issues.createComment({
161
- owner: context.repo.owner,
162
- repo: context.repo.repo,
163
- issue_number: issueNumber,
164
- body: `✅ Workspace has been successfully started! You can access it [here](${workspaceUrl}).`
165
- });
68
+ node "${{ github.action_path }}/dist/index.js"
166
69
167
70
- name : Comment failure
168
71
if : always() && (failure() || cancelled())
169
72
uses : actions/github-script@v6
170
73
with :
171
74
github-token : ${{ inputs.github-token }}
172
75
script : |
173
- const issueNumber = Number('${{ inputs.github-issue-number }}');
174
- const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}` ;
76
+ const commentId = Number('${{ steps.initial-comment.outputs.comment_id }}');
77
+ const runUrl = '${{ steps.initial-comment.outputs.run_url }}' ;
175
78
const errorMsg = process.env["ERROR_MSG"];
176
- await github.rest.issues.createComment ({
79
+ await github.rest.issues.updateComment ({
177
80
owner: context.repo.owner,
178
81
repo: context.repo.repo,
179
- issue_number: issueNumber ,
180
- body: "❌ " + (errorMsg ?? `Failed to start workspace. Please check the [action logs](${runUrl}) for details.`)
82
+ comment_id: commentId ,
83
+ body: "❌ " + (errorMsg ?? `Failed to start the workspace. Please check the [action logs](${runUrl}) for details.`)
181
84
});
0 commit comments