|
42 | 42 | result-encoding: string |
43 | 43 | - run: | |
44 | 44 | 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 |
46 | 47 | echo $'::error::\u274C' "Expected '$expected', got ${{steps.relative-require.outputs.result}}" |
47 | 48 | exit 1 |
48 | 49 | fi |
@@ -154,22 +155,54 @@ jobs: |
154 | 155 | return endpoint({}).headers['user-agent'] |
155 | 156 | result-encoding: string |
156 | 157 | - 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 |
157 | 160 | 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" |
161 | 164 | exit 1 |
162 | 165 | fi |
163 | 166 | 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" |
167 | 170 | exit 1 |
168 | 171 | fi |
169 | 172 | 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}}" |
173 | 206 | exit 1 |
174 | 207 | fi |
175 | 208 | echo $'\u2705 Test passed' | tee -a $GITHUB_STEP_SUMMARY |
|
0 commit comments