Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105018,7 +105018,7 @@ function buildReusableUserData({ runnerVersion, owner, repo, label, githubRegist
'UD=$(curl -fsS -H "X-aws-ec2-metadata-token: $IMDS_TOKEN" "http://169.254.169.254/latest/user-data" 2>/dev/null || true)',
'GH_TOKEN=$(printf \'%s\\n\' "$UD" | sed -n "s/^GH_TOKEN=\'\\(.*\\)\'$/\\1/p" | head -n1)',
'GH_LABEL=$(printf \'%s\\n\' "$UD" | sed -n "s/^GH_LABEL=\'\\(.*\\)\'$/\\1/p" | head -n1)',
'GH_REPO_URL=$(printf \'%s\\n\' "$UD" | sed -n "s#^GH_REPO_URL=\'\\(.*\\)\'$#\\1#p" | head -n1)',
'GH_REPO_URL=$(printf \'%s\\n\' "$UD" | sed -n "s,^GH_REPO_URL=\'\\(.*\\)\'$,\\1,p" | head -n1)',
'cd /home/runner/actions-runner',
'rm -f .runner .credentials .credentials_rsaparams',
'gh_runner_phone_home configuring',
Expand Down
2 changes: 1 addition & 1 deletion src/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function buildReusableUserData({ runnerVersion, owner, repo, label, githubRegist
'UD=$(curl -fsS -H "X-aws-ec2-metadata-token: $IMDS_TOKEN" "http://169.254.169.254/latest/user-data" 2>/dev/null || true)',
'GH_TOKEN=$(printf \'%s\\n\' "$UD" | sed -n "s/^GH_TOKEN=\'\\(.*\\)\'$/\\1/p" | head -n1)',
'GH_LABEL=$(printf \'%s\\n\' "$UD" | sed -n "s/^GH_LABEL=\'\\(.*\\)\'$/\\1/p" | head -n1)',
'GH_REPO_URL=$(printf \'%s\\n\' "$UD" | sed -n "s#^GH_REPO_URL=\'\\(.*\\)\'$#\\1#p" | head -n1)',
'GH_REPO_URL=$(printf \'%s\\n\' "$UD" | sed -n "s,^GH_REPO_URL=\'\\(.*\\)\'$,\\1,p" | head -n1)',
'cd /home/runner/actions-runner',
'rm -f .runner .credentials .credentials_rsaparams',
'gh_runner_phone_home configuring',
Expand Down
33 changes: 33 additions & 0 deletions tests/warmpool.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Tests for warm-pool (reuse: stop) support: findStoppedPoolInstance strict
// matching, warmStartInstance ordering, stop/cycle helpers, and the per-boot
// re-registration hook in the generated user-data.
const { execFileSync } = require('child_process');

const mockSend = jest.fn();
jest.mock('@aws-sdk/client-ec2', () => ({
EC2Client: jest.fn(() => ({ send: mockSend })),
Expand Down Expand Up @@ -185,4 +187,35 @@ describe('buildUserData — reuse: stop variant', () => {
expect(ud).not.toContain('gh-runner.service');
expect(ud).not.toContain('/opt/gh-runner-register.sh');
});

test('GH_REPO_URL extraction survives the sed-delimiter/$# collision (regression, #63)', () => {
const ud = aws.buildUserData({ ...args, reuse: 'stop' });

// Pull the real GH_REPO_URL=$(... sed ...) line straight out of the
// generated script, so this test exercises the actual shipped code
// rather than a hand-reimplementation of it.
const marker = 'GH_REPO_URL=$(printf';
const start = ud.indexOf(marker);
expect(start).toBeGreaterThan(-1);
const end = ud.indexOf('\n', start);
expect(end).toBeGreaterThan(start);
const extractionLine = ud.slice(start, end);

// Run that exact line under 'set -euo pipefail' with a controlled IMDS
// user-data value, the same shape the real registerScript reads via
// `UD=$(curl ... /latest/user-data)`. If the sed delimiter collides with
// bash's `$#` special parameter (as `#` does), the sed invocation is
// malformed, the pipeline fails, and the assignment aborts the script
// under `set -e` before GH_REPO_URL is ever printed.
const script = [
'#!/bin/bash',
'set -euo pipefail',
"UD=\"GH_REPO_URL='https://github.com/foo/bar'\"",
extractionLine,
'printf \'%s\' "$GH_REPO_URL"',
].join('\n');

const result = execFileSync('bash', ['-c', script]).toString();
expect(result).toBe('https://github.com/foo/bar');
});
});