Skip to content

Commit

Permalink
fallback to REST API to download repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsciple committed Dec 10, 2019
1 parent 5881116 commit a60eac9
Show file tree
Hide file tree
Showing 10 changed files with 4,029 additions and 833 deletions.
47 changes: 34 additions & 13 deletions .github/workflows/test.yml
Expand Up @@ -8,18 +8,18 @@ on:
- releases/*

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1 # todo: switch to v2
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm run pack
- run: npm run gendocs
- name: Verify no unstaged changes
run: __test__/verify-no-unstaged-changes.sh
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v1 # todo: switch to v2
# - run: npm ci
# - run: npm run build
# - run: npm run format-check
# - run: npm run lint
# - run: npm run pack
# - run: npm run gendocs
# - name: Verify no unstaged changes
# run: __test__/verify-no-unstaged-changes.sh

test:
strategy:
Expand All @@ -30,7 +30,7 @@ jobs:
steps:
# Clone this repo
- name: Checkout
uses: actions/checkout@v1 # todo: switch to V2
uses: actions/checkout@v2-beta

# Basic checkout
- name: Basic checkout
Expand Down Expand Up @@ -81,3 +81,24 @@ jobs:
- name: Verify LFS
shell: bash
run: __test__/verify-lfs.sh

test-job-container:
runs-on: ubuntu-latest
container: pstauffer/curl:latest
steps:
# Clone this repo
# todo: after v2-beta contains the latest changes, switch this to "uses: actions/checkout@v2-beta". Also check if can switch to "alpine:latest"
- name: Checkout
run: |
curl --location --user token:${{ github.token }} --output checkout.tar.gz https://api.github.com/repos/actions/checkout/tarball/${{ github.sha }}
tar -xzf checkout.tar.gz
mv */* ./
# Basic checkout
- name: Basic checkout
uses: ./
with:
ref: test-data/v2/basic
path: basic
- name: Verify basic
run: __test__/verify-basic.sh container
88 changes: 88 additions & 0 deletions __test__/retry-helper.test.ts
@@ -0,0 +1,88 @@
const mockCore = jest.genMockFromModule('@actions/core') as any
mockCore.info = (message: string) => {
info.push(message)
}
let info: string[]
let retryHelper: any

describe('retry-helper tests', () => {
beforeAll(() => {
// Mocks
jest.setMock('@actions/core', mockCore)

// Now import
const retryHelperModule = require('../lib/retry-helper')
retryHelper = new retryHelperModule.RetryHelper(3, 0, 0)
})

beforeEach(() => {
// Reset info
info = []
})

afterAll(() => {
// Reset modules
jest.resetModules()
})

it('first attempt succeeds', async () => {
const actual = await retryHelper.execute(async () => {
return 'some result'
})
expect(actual).toBe('some result')
expect(info).toHaveLength(0)
})

it('second attempt succeeds', async () => {
let attempts = 0
const actual = await retryHelper.execute(() => {
if (++attempts == 1) {
throw new Error('some error')
}

return Promise.resolve('some result')
})
expect(attempts).toBe(2)
expect(actual).toBe('some result')
expect(info).toHaveLength(2)
expect(info[0]).toBe('some error')
expect(info[1]).toMatch(/Waiting .+ seconds before trying again/)
})

it('third attempt succeeds', async () => {
let attempts = 0
const actual = await retryHelper.execute(() => {
if (++attempts < 3) {
throw new Error(`some error ${attempts}`)
}

return Promise.resolve('some result')
})
expect(attempts).toBe(3)
expect(actual).toBe('some result')
expect(info).toHaveLength(4)
expect(info[0]).toBe('some error 1')
expect(info[1]).toMatch(/Waiting .+ seconds before trying again/)
expect(info[2]).toBe('some error 2')
expect(info[3]).toMatch(/Waiting .+ seconds before trying again/)
})

it('all attempts fail succeeds', async () => {
let attempts = 0
let error: Error = (null as unknown) as Error
try {
await retryHelper.execute(() => {
throw new Error(`some error ${++attempts}`)
})
} catch (err) {
error = err
}
expect(error.message).toBe('some error 3')
expect(attempts).toBe(3)
expect(info).toHaveLength(4)
expect(info[0]).toBe('some error 1')
expect(info[1]).toMatch(/Waiting .+ seconds before trying again/)
expect(info[2]).toBe('some error 2')
expect(info[3]).toMatch(/Waiting .+ seconds before trying again/)
})
})
22 changes: 18 additions & 4 deletions __test__/verify-basic.sh
@@ -1,10 +1,24 @@
#!/bin/bash
#!/bin/sh

if [ ! -f "./basic/basic-file.txt" ]; then
echo "Expected basic file does not exist"
exit 1
fi

# Verify auth token
cd basic
git fetch
if [ "$1" = "container" ]; then
# Verify no .git folder
if [ -d "./basic/.git" ]; then
echo "Did not expect ./basic/.git folder to exist"
exit 1
fi
else
# Verify .git folder
if [ ! -d "./basic/.git" ]; then
echo "Expected ./basic/.git folder to exist"
exit 1
fi

# Verify auth token
cd basic
git fetch --depth=1
fi

0 comments on commit a60eac9

Please sign in to comment.