Skip to content

Commit 48d2ff8

Browse files
authored
feat: add message and ref outputs (#4)
1 parent b63d6ba commit 48d2ff8

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

.github/workflows/integration-tests.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,22 @@ jobs:
6262
script: |
6363
const assert = require('node:assert');
6464
65+
const message = 'Test new ref commit';
6566
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.commit-new-ref.outputs.sha }}'];
6667
6768
// Fetch the commit by both ref and sha
6869
for (const ref of refs) {
6970
const { data } = await github.rest.repos.getCommit({
7071
owner: context.repo.owner,
7172
repo: context.repo.repo,
72-
ref: 'integration-test-playground-${{ github.run_id }}-${{ github.run_number }}',
73+
ref,
7374
});
7475
76+
assert.strictEqual('${{ steps.commit-new-ref.outputs.message }}', message, 'Expected correct message output');
77+
assert.strictEqual('${{ steps.commit-new-ref.outputs.ref }}', refs[0], 'Expected correct ref output');
7578
assert.strictEqual('${{ steps.commit-new-ref.outputs.ref-operation }}', 'created', 'Expected correct ref operation');
7679
assert.strictEqual(data.sha, '${{ steps.commit-new-ref.outputs.sha }}', 'Expected sha for commit to match');
77-
assert.strictEqual(data.commit.message, 'Test new ref commit', 'Expected commit message to match');
80+
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
7881
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
7982
}
8083
@@ -107,19 +110,22 @@ jobs:
107110
script: |
108111
const assert = require('node:assert');
109112
113+
const message = 'Test updating existing ref';
110114
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.update-existing-ref.outputs.sha }}'];
111115
112116
// Fetch the commit by both ref and sha
113117
for (const ref of refs) {
114118
const { data } = await github.rest.repos.getCommit({
115119
owner: context.repo.owner,
116120
repo: context.repo.repo,
117-
ref: 'integration-test-playground-${{ github.run_id }}-${{ github.run_number }}',
121+
ref,
118122
});
119123
124+
assert.strictEqual('${{ steps.update-existing-ref.outputs.message }}', message, 'Expected correct message output');
125+
assert.strictEqual('${{ steps.update-existing-ref.outputs.ref }}', refs[0], 'Expected correct ref output');
120126
assert.strictEqual('${{ steps.update-existing-ref.outputs.ref-operation }}', 'updated', 'Expected correct ref operation');
121127
assert.strictEqual(data.sha, '${{ steps.update-existing-ref.outputs.sha }}', 'Expected sha for commit to match');
122-
assert.strictEqual(data.commit.message, 'Test updating existing ref', 'Expected commit message to match');
128+
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
123129
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
124130
}
125131
@@ -146,19 +152,22 @@ jobs:
146152
script: |
147153
const assert = require('node:assert');
148154
155+
const message = 'Test updating existing ref (again)';
149156
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.update-existing-ref-2.outputs.sha }}'];
150157
151158
// Fetch the commit by both ref and sha
152159
for (const ref of refs) {
153160
const { data } = await github.rest.repos.getCommit({
154161
owner: context.repo.owner,
155162
repo: context.repo.repo,
156-
ref: 'integration-test-playground-${{ github.run_id }}-${{ github.run_number }}',
163+
ref,
157164
});
158165
166+
assert.strictEqual('${{ steps.update-existing-ref-2.outputs.message }}', message, 'Expected correct message output');
167+
assert.strictEqual('${{ steps.update-existing-ref-2.outputs.ref }}', refs[0], 'Expected correct ref output');
159168
assert.strictEqual('${{ steps.update-existing-ref-2.outputs.ref-operation }}', 'updated', 'Expected correct ref operation');
160169
assert.strictEqual(data.sha, '${{ steps.update-existing-ref-2.outputs.sha }}', 'Expected sha for commit to match');
161-
assert.strictEqual(data.commit.message, 'Test updating existing ref (again)', 'Expected commit message to match');
170+
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
162171
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
163172
}
164173
@@ -200,19 +209,22 @@ jobs:
200209
script: |
201210
const assert = require('node:assert');
202211
212+
const message = 'Test updating existing ref (force)';
203213
const refs = ['integration-test-playground-${{ github.run_id }}-${{ github.run_number }}', '${{ steps.force-update-existing-ref.outputs.sha }}'];
204214
205215
// Fetch the commit by both ref and sha
206216
for (const ref of refs) {
207217
const { data } = await github.rest.repos.getCommit({
208218
owner: context.repo.owner,
209219
repo: context.repo.repo,
210-
ref: 'integration-test-playground-${{ github.run_id }}-${{ github.run_number }}',
220+
ref,
211221
});
212222
223+
assert.strictEqual('${{ steps.force-update-existing-ref.outputs.message }}', message, 'Expected correct message output');
224+
assert.strictEqual('${{ steps.force-update-existing-ref.outputs.ref }}', refs[0], 'Expected correct ref output');
213225
assert.strictEqual('${{ steps.force-update-existing-ref.outputs.ref-operation }}', 'updated', 'Expected correct ref operation');
214226
assert.strictEqual(data.sha, '${{ steps.force-update-existing-ref.outputs.sha }}', 'Expected sha for commit to match');
215-
assert.strictEqual(data.commit.message, 'Test updating existing ref (force)', 'Expected commit message to match');
227+
assert.strictEqual(data.commit.message, message, 'Expected commit message to match');
216228
assert.strictEqual(data.commit.verification.verified, true, 'Expected commit to be verified');
217229
}
218230

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ jobs:
6868

6969
### Outputs
7070

71+
- `message` - The commit message
72+
- `ref` - The associated Git reference
7173
- `ref-operation` - Which operation was performed on the ref: `created` or `updated`. Has no value if there were no changes to commit.
7274
- `sha` - SHA for the commit
7375

__tests__/main.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ describe('action', () => {
131131
})
132132
);
133133

134-
expect(core.setOutput).toHaveBeenCalledTimes(2);
134+
expect(core.setOutput).toHaveBeenCalledTimes(4);
135+
expect(core.setOutput).toHaveBeenCalledWith('message', message);
136+
expect(core.setOutput).toHaveBeenCalledWith('ref', ref);
135137
expect(core.setOutput).toHaveBeenCalledWith('ref-operation', 'updated');
136138
expect(core.setOutput).toHaveBeenCalledWith('sha', commitSha);
137139
});
@@ -173,7 +175,9 @@ describe('action', () => {
173175
})
174176
);
175177

176-
expect(core.setOutput).toHaveBeenCalledTimes(2);
178+
expect(core.setOutput).toHaveBeenCalledTimes(4);
179+
expect(core.setOutput).toHaveBeenCalledWith('message', message);
180+
expect(core.setOutput).toHaveBeenCalledWith('ref', ref);
177181
expect(core.setOutput).toHaveBeenCalledWith('ref-operation', 'updated');
178182
expect(core.setOutput).toHaveBeenCalledWith('sha', commitSha);
179183
});
@@ -198,7 +202,9 @@ describe('action', () => {
198202
expect(updateRef).toHaveBeenCalled();
199203
expect(createRef).not.toHaveBeenCalled();
200204

201-
expect(core.setOutput).toHaveBeenCalledTimes(2);
205+
expect(core.setOutput).toHaveBeenCalledTimes(4);
206+
expect(core.setOutput).toHaveBeenCalledWith('message', message);
207+
expect(core.setOutput).toHaveBeenCalledWith('ref', ref);
202208
expect(core.setOutput).toHaveBeenCalledWith('ref-operation', 'updated');
203209
expect(core.setOutput).toHaveBeenCalledWith('sha', commitSha);
204210
});
@@ -241,7 +247,9 @@ describe('action', () => {
241247
})
242248
);
243249

244-
expect(core.setOutput).toHaveBeenCalledTimes(2);
250+
expect(core.setOutput).toHaveBeenCalledTimes(4);
251+
expect(core.setOutput).toHaveBeenCalledWith('message', message);
252+
expect(core.setOutput).toHaveBeenCalledWith('ref', ref);
245253
expect(core.setOutput).toHaveBeenCalledWith('ref-operation', 'created');
246254
expect(core.setOutput).toHaveBeenCalledWith('sha', commitSha);
247255
});
@@ -327,7 +335,9 @@ describe('action', () => {
327335
);
328336
expect(createRef).not.toHaveBeenCalled();
329337

330-
expect(core.setOutput).toHaveBeenCalledTimes(2);
338+
expect(core.setOutput).toHaveBeenCalledTimes(4);
339+
expect(core.setOutput).toHaveBeenCalledWith('message', message);
340+
expect(core.setOutput).toHaveBeenCalledWith('ref', ref);
331341
expect(core.setOutput).toHaveBeenCalledWith('ref-operation', 'updated');
332342
expect(core.setOutput).toHaveBeenCalledWith('sha', commitSha);
333343
});

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
required: true
2727

2828
outputs:
29+
message:
30+
description: The commit message
31+
ref:
32+
description: The associated Git reference
2933
ref-operation:
3034
description: 'Which operation was performed on the ref: `created` or `updated`. Has no value if there were no changes to commit.'
3135
sha:

dist/index.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export async function run(): Promise<void> {
6565
const token = core.getInput('token', { required: true });
6666

6767
// Optional inputs
68-
const ref = `heads/${core.getInput('ref') || (await getHeadRef())}`;
68+
const ref = core.getInput('ref') || (await getHeadRef());
6969
const failOnNoChanges = core.getBooleanInput('fail-on-no-changes');
7070
const force = core.getBooleanInput('force');
7171

@@ -105,7 +105,7 @@ export async function run(): Promise<void> {
105105
await octokit.rest.git.updateRef({
106106
owner,
107107
repo,
108-
ref,
108+
ref: `heads/${ref}`,
109109
sha: newCommit.data.sha,
110110
force
111111
});
@@ -120,7 +120,7 @@ export async function run(): Promise<void> {
120120
await octokit.rest.git.createRef({
121121
owner,
122122
repo,
123-
ref: `refs/${ref}`,
123+
ref: `refs/heads/${ref}`,
124124
sha: newCommit.data.sha
125125
});
126126
core.setOutput('ref-operation', 'created');
@@ -130,6 +130,8 @@ export async function run(): Promise<void> {
130130
}
131131
}
132132

133+
core.setOutput('message', message);
134+
core.setOutput('ref', ref);
133135
core.setOutput('sha', newCommit.data.sha);
134136
} catch (error) {
135137
// Fail the workflow run if an error occurs

0 commit comments

Comments
 (0)