Skip to content

Commit 3f34d47

Browse files
authored
Merge pull request #11 from polarsignals/error-handling
Error handling
2 parents ad497b1 + c4bac7d commit 3f34d47

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

.github/workflows/github-actions-demo.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ jobs:
1313
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
1414
- name: Check out the code
1515
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
16-
- name: Extract branch name
17-
shell: bash
18-
run: echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >>$GITHUB_OUTPUT
19-
id: extract_branch
2016
- uses: ./ # Uses an action in the root directory.
2117
with:
2218
polarsignals_cloud_token: ${{ secrets.PSTOKEN }}
23-
labels: branch=${{ steps.extract_branch.outputs.branch }};gh_run_id=${{ github.run_id }}
24-
project_uuid: ${{ secrets.POLARSIGNALSPROJECTUUID }}
19+
labels: ref_name=${{ github.ref_name }};workflow=${{ github.workflow }};gh_run_id=${{ github.run_id }}
20+
project_uuid: 7a8644bb-3a90-4a02-be35-efcb6bba4a54
2521
github_token: ${{ secrets.GITHUB_TOKEN }}
2622
- name: Set up Go
2723
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ on: [push]
3838

3939
permissions:
4040
deployments: write
41+
contents: read
4142

4243
jobs:
4344
profile:
@@ -51,6 +52,6 @@ jobs:
5152
polarsignals_cloud_token: ${{ secrets.POLARSIGNALS_CLOUD_TOKEN }}
5253
project_uuid: 'your-project-uuid-here' # Don't use a secret for this, it's not sensitive, and otherwise the URL will be partially redacted.
5354
labels: ref_name=${{ github.ref_name }};workflow=${{ github.workflow }};gh_run_id=${{ github.run_id }}
54-
github_token: ${{ secrets.GITHUB_TOKEN }}
55+
github_token: "${{ github.token }}"
5556
```
5657

index.js

+38-23
Original file line numberDiff line numberDiff line change
@@ -205,33 +205,48 @@ async function post() {
205205
auth: github_token
206206
});
207207

208-
const deployment = await client.repos.createDeployment({
209-
owner,
210-
repo,
211-
ref,
212-
environment: 'polar-signals-cloud',
213-
required_contexts: [],
214-
auto_merge: false,
215-
description: 'Polar Signals Profiling Results',
216-
transient_environment: true,
217-
production_environment: false
218-
});
219-
220-
// Create a deployment status
221-
if (deployment.data.id) {
222-
const deploymentId = deployment.data.id;
223-
await client.repos.createDeploymentStatus({
208+
try {
209+
core.info('Creating deployment...');
210+
const deployment = await client.repos.createDeployment({
224211
owner,
225212
repo,
226-
deployment_id: deploymentId,
227-
state: 'success',
228-
description: 'Profiling data is available',
229-
environment_url: queryUrl,
230-
log_url: queryUrl,
231-
auto_inactive: true
213+
ref,
214+
environment: 'polar-signals-cloud',
215+
required_contexts: [],
216+
auto_merge: false,
217+
description: 'Polar Signals Profiling Results',
218+
transient_environment: true,
219+
production_environment: false
232220
});
233221

234-
core.info(`Created deployment with ID: ${deploymentId}`);
222+
// Create a deployment status
223+
if (deployment.data.id) {
224+
const deploymentId = deployment.data.id;
225+
core.info(`Deployment created with ID: ${deploymentId}. Creating deployment status...`);
226+
227+
try {
228+
await client.repos.createDeploymentStatus({
229+
owner,
230+
repo,
231+
deployment_id: deploymentId,
232+
state: 'success',
233+
description: 'Profiling data is available',
234+
environment_url: queryUrl,
235+
log_url: queryUrl,
236+
auto_inactive: true
237+
});
238+
239+
core.info(`Deployment status created successfully for ID: ${deploymentId}`);
240+
} catch (statusError) {
241+
core.error(`Failed to create deployment status: ${statusError.message}`);
242+
core.error(`Status error details: ${JSON.stringify(statusError)}`);
243+
}
244+
} else {
245+
core.warning('Deployment was created but no deployment ID was returned');
246+
}
247+
} catch (createError) {
248+
core.error(`Failed to create deployment: ${createError.message}`);
249+
core.error(`Create error details: ${JSON.stringify(createError)}`);
235250
}
236251
} else {
237252
core.info('Skipping GitHub deployment creation due to missing required parameters:');

0 commit comments

Comments
 (0)