Skip to content

Commit

Permalink
chore: more debugging...
Browse files Browse the repository at this point in the history
  • Loading branch information
FabiLo22 committed Oct 29, 2024
1 parent a249e3d commit 8947106
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 78 deletions.
92 changes: 56 additions & 36 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "typescript-action",
"description": "Givve Automatic Deployment",
"version": "v0.0.15",
"version": "v0.0.17",
"author": "PL Gutscheinsysteme GmbH",
"private": true,
"homepage": "https://github.com/actions/typescript-action",
Expand Down Expand Up @@ -72,7 +72,8 @@
"@octokit/rest": "^21.0.2",
"@types/lodash": "^4.17.11",
"axios": "^1.7.7",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class GitHub {
pull_number: core.getInput('pull_request')
}
)
console.log(error)

resolve(issue.labels.map((label: any) => label.name))
})
}
Expand Down
37 changes: 16 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core'
import { wait } from './wait.js'
import { checkOrWait } from './wait.js'
import { getLocks, setLock } from './semaphore.js'
import { GitHub } from './github.js'
import * as _ from 'lodash'
Expand All @@ -18,30 +18,15 @@ export async function run(): Promise<void> {
try {
const github = new GitHub()
await github.performAuth()
console.log('AUTHED')

const labels = await github.getLabels()
console.log(labels)
// Manual deployment, check locks
const locks = (await getLocks(component)).data.data
const activeLock = _.find(locks, {
component: component,
unlocked_by: null
})
core.debug(JSON.stringify(labels))

if (_.includes(labels, 'auto deploy')) {
if (activeLock) {
// There is a lock, so we check if we cancel or wait
if (activeLock.purpose !== 'manual deployment lock') {
// Some other deployment is running, so we wait
await wait(60000)
} else {
// manual deployment lock active. Abort!
core.setFailed('Manual deployment lock active!')
}
}
await checkOrWait()
} else {
const lock = await getLock()
// No lock, we need to lock deployment
if (!activeLock) {
if (!lock) {
const { error } = await setLock(component)
}

Expand All @@ -53,3 +38,13 @@ export async function run(): Promise<void> {
if (error instanceof Error) core.setFailed(error.message)
}
}

export async function getLock() {
// Manual deployment, check locks
const locks = (await getLocks(component)).data.data

return _.find(locks, {
component: component,
unlocked_by: null
})
}
1 change: 0 additions & 1 deletion src/semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function getLocks(component: string): Promise<any> {
}

export async function setLock(component: string): Promise<any> {
console.log('SET LOCK')
return axios.post(
semaphoreAPI +
`/api/products/5f7427d977b4b64aeabad92d/components/${component}/locks`,
Expand Down
32 changes: 21 additions & 11 deletions src/wait.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
/**
* Wait for a number of milliseconds.
* @param milliseconds The number of milliseconds to wait.
* @returns {Promise<string>} Resolves with 'done!' after the wait is over.
*/
export async function wait(milliseconds: number): Promise<string> {
return new Promise(resolve => {
if (isNaN(milliseconds)) {
throw new Error('milliseconds not a number')
}
import { getLock } from './main'
import * as core from '@actions/core'

setTimeout(() => resolve('done!'), milliseconds)
export async function checkOrWait(): Promise<string> {
return new Promise(async (resolve, reject) => {
await check(resolve, reject)
})
}

async function check(resolve: any, reject: any) {
const lock = await getLock()

if (!lock) {
resolve('Done!')
} else {
if (lock.purpose === 'manual deployment lock') {
// Some other deployment is running, so we wait
core.setFailed('Manual deployment lock active!')
reject('Locked')
}
}

setTimeout(check, 20000)
}

0 comments on commit 8947106

Please sign in to comment.