Compare commits

..

7 Commits

Author SHA1 Message Date
Ferenc Hammerl 0d44da2b87 Raw jq for actual version
Tag test / publish (push) Has been cancelled
Tag test / test (push) Has been cancelled
Tag test / Tag ${{ needs.test.outputs.sha }} with ${{ needs.test.outputs.tag }} (push) Has been cancelled
2023-03-07 11:11:44 +00:00
Ferenc Hammerl cb86beb23a BEtter tag format 2023-03-07 11:05:52 +00:00
Ferenc Hammerl 7edb0957cc Fix indentation 2023-03-07 10:51:42 +00:00
Ferenc Hammerl b92588fa7f Use constants and push for tag-test
Fix typo in releases.yml
2023-03-07 10:49:25 +00:00
Ferenc Hammerl 39e91a437a Fix indent 2023-03-07 10:44:40 +00:00
Ferenc Hammerl 4166af5b3e Fix typo 2023-03-07 10:43:17 +00:00
Ferenc Hammerl b8bef557c0 Tag commits on NPM releases with pkgname-v.x.y.z 2023-03-07 10:41:27 +00:00
4 changed files with 77 additions and 142 deletions
+29 -1
View File
@@ -9,11 +9,17 @@ on:
jobs:
test:
outputs:
sha: ${{ steps.commit.outputs.sha }}
tag: ${{ steps.tag.outputs.tag }}
runs-on: macos-latest
steps:
- name: setup repo
uses: actions/checkout@v3
- id: commit
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- id: tag
run: echo "tag=@actions/${{ github.event.inputs.package }}@$(cat packages/${{ github.event.inputs.package }}/package.json | jq -r .version" >> "$GITHUB_OUTPUT"
- name: verify package exists
run: ls packages/${{ github.event.inputs.package }}
@@ -77,4 +83,26 @@ jobs:
curl -X POST -H 'Content-type: application/json' --data '{"text":":dance: Successfully published a new version of ${{ github.event.inputs.package }}"}' $SLACK_WEBHOOK
env:
SLACK_WEBHOOK: ${{ secrets.SLACK }}
tag:
name: "Tag ${{ needs.test.outputs.sha }} with ${{ needs.test.outputs.tag }}"
runs-on: "macos-latest"
needs: [test, publish]
steps:
- uses: actions/checkout@v3
- name: Create tag
uses: actions/github-script@v6
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ needs.test.outputs.tag }}',
sha: '${{ needs.test.outputs.sha }}'
})
- name: notify slack on failure
if: failure()
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":":pb__failed: Publish of ${{ github.event.inputs.package }} was successful, but failed to tag commit ${{ needs.test.outputs.sha }} with version ${{ needs.test.outputs.tag }}"}' $SLACK_WEBHOOK
env:
SLACK_WEBHOOK: ${{ secrets.SLACK }}
+46
View File
@@ -0,0 +1,46 @@
name: Tag test
on: push
jobs:
test:
outputs:
sha: ${{ steps.commit.outputs.sha }}
tag: ${{ steps.tag.outputs.tag }}
runs-on: macos-latest
steps:
- name: setup repo
uses: actions/checkout@v3
- id: commit
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- id: tag
run: echo "tag=@actions/http-client@$(cat packages/http-client/package.json | jq -r .version)-test-tag" >> "$GITHUB_OUTPUT"
publish:
runs-on: macos-latest
needs: test
steps:
- name: skip publish
run: echo "skip publish"
tag:
name: "Tag ${{ needs.test.outputs.sha }} with ${{ needs.test.outputs.tag }}"
runs-on: "macos-latest"
needs: [test, publish]
steps:
- uses: actions/checkout@v3
- name: Create tag
uses: actions/github-script@v6
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ needs.test.outputs.tag }}',
sha: '${{ needs.test.outputs.sha }}'
})
# - name: notify slack on failure
# if: failure()
# run: |
# curl -X POST -H 'Content-type: application/json' --data '{"text":":pb__failed: Publish of ${{ github.event.inputs.package }} was successful, but failed to tag commit ${{ needs.test.outputs.sha }} with version ${{ needs.test.outputs.tag }}"}' $SLACK_WEBHOOK
# env:
# SLACK_WEBHOOK: ${{ secrets.SLACK }}
+2 -127
View File
@@ -28,7 +28,7 @@ describe('proxy', () => {
_clearVars()
})
afterEach(() => { })
afterEach(() => {})
afterAll(async () => {
_clearVars()
@@ -196,7 +196,7 @@ describe('proxy', () => {
expect(_proxyConnects).toEqual(['httpbin.org:80'])
})
it('HttpClient does basic http get request when bypass proxy', async () => {
it('HttoClient does basic http get request when bypass proxy', async () => {
process.env['http_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
@@ -258,133 +258,8 @@ describe('proxy', () => {
expect(agent.proxyOptions.port).toBe('8080')
expect(agent.proxyOptions.proxyAuth).toBe('user:password')
})
// unit tests from actions/runner
it('should prefer lowercase over uppercase ENVs', async () => {
process.env['http_proxy'] = 'http://127.0.0.1:7777'
process.env['HTTP_PROXY'] = 'http://127.0.0.1:8888'
process.env['https_proxy'] = 'https://127.0.0.1:8888'
process.env['HTTPS_PROXY'] = 'https://127.0.0.1:7777'
const httpClient = new httpm.HttpClient()
const httpAgent: any = httpClient.getAgent('http://some-url')
expect(httpAgent.proxyOptions.host).toBe('127.0.0.1')
expect(httpAgent.proxyOptions.port).toBe('7777')
const httpsAgent: any = httpClient.getAgent('https://some-url')
expect(httpsAgent.proxyOptions.host).toBe('127.0.0.1')
expect(httpsAgent.proxyOptions.port).toBe('8888')
})
it('should not set proxy on invalid input', async () => {
process.env['http_proxy'] = '127.0.0.1:7777'
process.env['https_proxy'] = '127.0.0.1:8888'
const httpClient = new httpm.HttpClient()
// Different from actions/runner, we throw an error here while the runner proceeds without a proxy
expect(() => httpClient.getAgent('http://some-url')).toThrow()
expect(() => httpClient.getAgent('https://some-url')).toThrow()
})
it('should bypass no_proxy hosts', async () => {
process.env['http_proxy'] = '127.0.0.1:7777'
process.env['https_proxy'] = '127.0.0.1:8888'
process.env['no_proxy'] = 'github.com, .google.com, example.com:444, 192.168.0.123:123, 192.168.1.123'
expect(pm.checkBypass(new URL('https://actions.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://ggithub.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://github.comm'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://google.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://example.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('http://example.com:333'))).toBeFalsy();
expect(pm.checkBypass(new URL('http://192.168.0.123:123'))).toBeTruthy(); // DIFF
expect(pm.checkBypass(new URL('http://192.168.1.123/home'))).toBeTruthy(); // DIFF
expect(pm.checkBypass(new URL('https://github.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://GITHUB.COM'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://github.com/owner/repo'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://actions.github.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://mails.google.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://MAILS.GOOGLE.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://mails.v2.google.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://mails.v2.v3.google.com/inbox'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://example.com:444'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://example.com:444'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://example.COM:444'))).toBeTruthy()
})
})
it('should not use http_proxy for https requests if https_proxy is not set', async () => {
process.env['http_proxy'] = 'http://127.0.0.1:7777/'
expect(pm.getProxyUrl(new URL('http://example.com'))).toBeDefined()
expect(pm.getProxyUrl(new URL('https://example.com'))).toBeUndefined()
})
it('HttpClient does basic https get request when bypass proxy', async () => {
process.env['https_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'https://httpbin.org/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toHaveLength(0)
})
it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => {
// setup a server listening on localhost:8091
var server = http.createServer(function (request, response) {
response.writeHead(200);
request.pipe(response);
});
await server.listen(8091)
try {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'http://localhost:8091'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
expect(body).toEqual('');
// proxy at _proxyUrl was ignored
expect(_proxyConnects).toEqual([])
}
finally {
await server.close()
}
})
it('HttpClient does basic https get request when bypass proxy', async () => {
process.env['https_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'https://httpbin.org/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toHaveLength(0)
})
it('should not use https_proxy for http requests if http_proxy is not set', async () => {
process.env['https_proxy'] = 'https://127.0.0.1:7777/'
expect(pm.getProxyUrl(new URL('http://example.com'))).toBeUndefined()
expect(pm.getProxyUrl(new URL('https://example.com'))).toBeDefined()
})
// it('should detect loopback ip addresses', async () => {
// process.env['http_proxy'] = 'http://nonlocal.faraway.com:7777/'
// expect(pm.getProxyUrl(new URL('http://localhost'))).toBeUndefined()
// })
function _clearVars(): void {
delete process.env.http_proxy
delete process.env.HTTP_PROXY
-14
View File
@@ -25,11 +25,6 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
const reqHost = reqUrl.hostname
if (isLoopbackAddress(reqHost)) {
return true
}
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''
if (!noProxy) {
return false
@@ -71,12 +66,3 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
function isLoopbackAddress(host: string): boolean {
const hostUpper = host.toUpperCase()
return (
hostUpper === 'LOCALHOST' ||
hostUpper.startsWith('127.') ||
hostUpper.startsWith('::1')
)
}