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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- uses: actions/setup-node@v4
- run: corepack enable && yarn --version
- run: yarn install
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
on: [push]
on:
push:

name: Test Workflow

Expand All @@ -9,10 +10,23 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4.3.0
with:
node-version: '20'
- name: Setup Yarn
run: |
corepack enable
corepack prepare yarn@4.2.1 --activate
- name: Install
run: yarn install
- name: Build
run: yarn build
- uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
client-id: ${{ secrets.DVC_CLIENT_ID }}
client-secret: ${{ secrets.DVC_CLIENT_SECRET }}
project-key: default
project-key: git-hub-actions-integration-tests
16 changes: 9 additions & 7 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,26 @@ describe('authenticate', () => {
) as jest.Mock;

const returnedToken = await action.authenticate('mock-client-id', 'mock-client-secret')
const formData = new FormData()
formData.append('grant_type', 'client_credentials')
formData.append('client_id', 'mock-client-id')
formData.append('client_secret', 'mock-client-secret')
formData.append('audience', 'https://api.devcycle.com/')
const params = new URLSearchParams({
grant_type: 'client_credentials',
client_id: 'mock-client-id',
client_secret: 'mock-client-secret',
audience: 'https://api.devcycle.com/'
})


expect(fetch).toBeCalledWith(
'https://auth.devcycle.com/oauth/token',
expect.objectContaining({body: formData}))
expect.objectContaining({body: params.toString()}))
expect(returnedToken).toEqual('123')
})

it('fails if an error is thrown during authentication', async () => {
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve('Some error'),
ok: false
ok: false,
status: 401
}),
) as jest.Mock;
const authenticate = () => action.authenticate('mock-client-id', 'mock-client-secret')
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"typescript": "^4.5.4"
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1"
"@actions/github": "^6.0.0"
},
"packageManager": "yarn@4.2.1"
}
19 changes: 11 additions & 8 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function run() {
}

try {
await exec('npm', ['install', '-g', '@devcycle/cli@5.16.2'])
await exec('npm', ['install', '-g', '@devcycle/cli@5.20.2'])

const output = await getExecOutput(
'dvc',
Expand All @@ -40,17 +40,20 @@ export async function run() {
}

export const authenticate = async (client_id: string, client_secret: string): Promise<string> => {
const url = new URL('/oauth/token', AUTH_URL)


try {
const formData = new FormData();
formData.append('grant_type', 'client_credentials');
formData.append('client_id',client_id);
formData.append('client_secret',client_secret);
formData.append('audience','https://api.devcycle.com/');
const params = new URLSearchParams({
grant_type: 'client_credentials',
client_id,
client_secret,
audience: API_URL
})
const url = new URL(`/oauth/token`, AUTH_URL)
const resp = await fetch(url.href, {
method: 'POST',
body: formData,
body: params.toString(),
headers: {'content-type': 'application/x-www-form-urlencoded'}
})
if (!resp.ok) {
throw new Error('Failed to authenticate with the DevCycle API. Check your credentials.')
Expand Down
6 changes: 3 additions & 3 deletions test-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function useDVCVariable() {

// Fetch variable values using the identifier key coupled with a default value
// The default value can be of type string, boolean, number, or object
const dvcVariableNumber = dvcClient.variable('test-feature-number', 10)
const dvcVariableString = dvcClient.variable('test-feature-string', '10')
const dvcVariableJson = dvcClient.variable('test-feature-json', {})
const dvcVariableNumber = dvcClient.variable('gha-ff-code-usages', 10)
const dvcVariableString = dvcClient.variable('gha-ff-code-usages-string', '10')
const dvcVariableJson = dvcClient.variable('gha-ff-code-usages-json', {})
}
Loading