Skip to content

Commit c17d55b

Browse files
committed
ci: add getOctokit integration test job
1 parent a047196 commit c17d55b

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

.github/workflows/integration.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ jobs:
4242
result-encoding: string
4343
- run: |
4444
echo "- Validating relative require output"
45-
if [[ "${{steps.relative-require.outputs.result}}" != "@actions/github-script" ]]; then
45+
expected="@actions/github-script"
46+
if [[ "${{steps.relative-require.outputs.result}}" != "$expected" ]]; then
4647
echo $'::error::\u274C' "Expected '$expected', got ${{steps.relative-require.outputs.result}}"
4748
exit 1
4849
fi
@@ -154,22 +155,54 @@ jobs:
154155
return endpoint({}).headers['user-agent']
155156
result-encoding: string
156157
- run: |
158+
# User-agent format: <prefix> [actions_orchestration_id/<id>] octokit-core.js/<version> ...
159+
# When ACTIONS_ORCHESTRATION_ID is set, the orchestration ID is inserted after the prefix
157160
echo "- Validating user-agent default"
158-
expected="actions/github-script octokit-core.js/"
159-
if [[ "${{steps.user-agent-default.outputs.result}}" != "$expected"* ]]; then
160-
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-default.outputs.result}}"
161+
ua="${{steps.user-agent-default.outputs.result}}"
162+
if [[ "$ua" != "actions/github-script"* ]] || [[ "$ua" != *"octokit-core.js/"* ]]; then
163+
echo $'::error::\u274C' "Expected user-agent to start with 'actions/github-script' and contain 'octokit-core.js/', got $ua"
161164
exit 1
162165
fi
163166
echo "- Validating user-agent set to a value"
164-
expected="foobar octokit-core.js/"
165-
if [[ "${{steps.user-agent-set.outputs.result}}" != "$expected"* ]]; then
166-
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-set.outputs.result}}"
167+
ua="${{steps.user-agent-set.outputs.result}}"
168+
if [[ "$ua" != "foobar"* ]] || [[ "$ua" != *"octokit-core.js/"* ]]; then
169+
echo $'::error::\u274C' "Expected user-agent to start with 'foobar' and contain 'octokit-core.js/', got $ua"
167170
exit 1
168171
fi
169172
echo "- Validating user-agent set to an empty string"
170-
expected="actions/github-script octokit-core.js/"
171-
if [[ "${{steps.user-agent-empty.outputs.result}}" != "$expected"* ]]; then
172-
echo $'::error::\u274C' "Expected user-agent to start with '$expected', got ${{steps.user-agent-empty.outputs.result}}"
173+
ua="${{steps.user-agent-empty.outputs.result}}"
174+
if [[ "$ua" != "actions/github-script"* ]] || [[ "$ua" != *"octokit-core.js/"* ]]; then
175+
echo $'::error::\u274C' "Expected user-agent to start with 'actions/github-script' and contain 'octokit-core.js/', got $ua"
176+
exit 1
177+
fi
178+
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY
179+
180+
test-get-octokit:
181+
name: 'Integration test: getOctokit with token'
182+
runs-on: ubuntu-latest
183+
steps:
184+
- uses: actions/checkout@v4
185+
- uses: ./.github/actions/install-dependencies
186+
- id: secondary-client
187+
name: Create a second client with getOctokit
188+
uses: ./
189+
env:
190+
APP_TOKEN: ${{ github.token }}
191+
with:
192+
script: |
193+
const appOctokit = getOctokit(process.env.APP_TOKEN)
194+
const {data} = await appOctokit.rest.repos.get({
195+
owner: context.repo.owner,
196+
repo: context.repo.repo
197+
})
198+
199+
return `${appOctokit !== github}:${data.full_name}`
200+
result-encoding: string
201+
- run: |
202+
echo "- Validating secondary client output"
203+
expected="true:${{ github.repository }}"
204+
if [[ "${{steps.secondary-client.outputs.result}}" != "$expected" ]]; then
205+
echo $'::error::\u274C' "Expected '$expected', got ${{steps.secondary-client.outputs.result}}"
173206
exit 1
174207
fi
175208
echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)