diff --git a/.github/workflows/action_test.yml b/.github/workflows/action_test.yml index 6e4a6f2..5a21356 100644 --- a/.github/workflows/action_test.yml +++ b/.github/workflows/action_test.yml @@ -66,17 +66,37 @@ jobs: printenv #---------------------------------------------------------------------------------------------- + # Test findBoard + - name: TestFind + uses: Analog-Devices-MSDK/btm-ci-scripts/actions/find-board@v1 + id: boardGet + with: + target: | + MAX32655 + MAX32665 + group: APP + + - name: GetFound + run: | + echo $MAX32655 + echo $MAX32665 + env: + MAX32655: ${{ steps.boardGet.outputs.board1 }} + MAX32665: ${{ steps.boardGet.outputs.board2 }} + + #---------------------------------------------------------------------------------------------- # Test lockBoard --> lock action - name: TestLock - uses: Analog-Devices-MSDK/btm-ci-scripts/actions/lock-board@main + uses: Analog-Devices-MSDK/btm-ci-scripts/actions/lock-board@v1 with: boards: | max32655_board1 + max32655_board2 lock: true # #---------------------------------------------------------------------------------------------- # Test OCDFlash action - name: TestFlash - uses: Analog-Devices-MSDK/btm-ci-scripts/actions/ocdflash@main + uses: Analog-Devices-MSDK/btm-ci-scripts/actions/ocdflash@v1 with: board: | max32655_board1 @@ -86,24 +106,22 @@ jobs: # # #---------------------------------------------------------------------------------------------- # Test OCDReset action - name: TestReset - uses: Analog-Devices-MSDK/btm-ci-scripts/actions/ocdreset@main + uses: Analog-Devices-MSDK/btm-ci-scripts/actions/ocdreset@v1 with: board: | max32655_board1 #---------------------------------------------------------------------------------------------- # Test OCDErase action - name: TestErase - uses: Analog-Devices-MSDK/btm-ci-scripts/actions/ocderase@main + uses: Analog-Devices-MSDK/btm-ci-scripts/actions/ocderase@v1 with: board: | max32655_board1 - has_two_flash_banks: false #---------------------------------------------------------------------------------------------- # Test lockBoard --> unlock action - name: TestUnlock if: always() - uses: Analog-Devices-MSDK/btm-ci-scripts/actions/lock-board@main + uses: Analog-Devices-MSDK/btm-ci-scripts/actions/lock-board@v1 with: - boards: | - max32655_board1 + all_owned: true lock: false diff --git a/Resource_Share/src/resource_manager/resource_manager.py b/Resource_Share/src/resource_manager/resource_manager.py index 641385a..ecab627 100644 --- a/Resource_Share/src/resource_manager/resource_manager.py +++ b/Resource_Share/src/resource_manager/resource_manager.py @@ -464,13 +464,15 @@ def print_applicable_items( applicable_items_open = [] applicable_items_inuse = [] for rname in self.resources: - if target : - if self.get_item_value(f"{rname}.target") != target.upper(): - continue - if group: - if self.get_item_value(f"{rname}.group") != group.upper(): - continue - + try: + if target : + if self.get_item_value(f"{rname}.target") != target.upper(): + continue + if group: + if self.get_item_value(f"{rname}.group") != group.upper(): + continue + except KeyError: + continue if self.resource_in_use(rname): applicable_items_inuse.append(rname) else: diff --git a/Resource_Share/src/resource_manager_cli.py b/Resource_Share/src/resource_manager_cli.py index b6002a4..64b8869 100644 --- a/Resource_Share/src/resource_manager_cli.py +++ b/Resource_Share/src/resource_manager_cli.py @@ -86,7 +86,7 @@ def config_cli() -> argparse.Namespace: default=[], action="extend", nargs="*", - help="Name of resource to unlock per boards_config.json", + help="Name of board to unlock per boards_config.json", ) parser.add_argument( @@ -107,7 +107,7 @@ def config_cli() -> argparse.Namespace: default=[], action="extend", nargs="*", - help="Name of resource to lock per boards_config.json", + help="Name of board to lock per boards_config.json", ) parser.add_argument( @@ -141,7 +141,7 @@ def config_cli() -> argparse.Namespace: "-f", "--find-board", nargs=2, - default=["", ""], + default=None, help="Find a board which matches the criteria TARGET GROUP", ) parser.add_argument( @@ -182,20 +182,20 @@ def main(): resource_manager.print_usage() if args.unlock_all: - print("Unlocking all resources!") + print("Unlocking all boards!") resource_manager.unlock_all_resources() sys.exit(0) if lock_boards: - print(f"Attempting to lock resources {lock_boards}") + print(f"Attempting to lock all boards {lock_boards}") could_lock = resource_manager.lock_resources(lock_boards, args.owner) if could_lock: - print("Successfully locked resources") + print("Successfully locked boards") sys.exit(0) else: - print("Failed to lock all resources") + print("Failed to lock all boards") sys.exit(-1) if unlock_boards: @@ -224,6 +224,9 @@ def main(): for resource in resources: print(resource) + if args.find_board is not None: + resource_manager.print_applicable_items(target=args.find_board[0], group=args.find_board[1]) + sys.exit(0) diff --git a/actions/common/index.js b/actions/common/index.js index 834d558..e437294 100644 --- a/actions/common/index.js +++ b/actions/common/index.js @@ -1,5 +1,6 @@ const { spawn } = require('child_process'); const fs = require('fs'); +const path = require('path'); const findTargetDirectory = function(dir, target) { const files = fs.readdirSync(dir); @@ -10,22 +11,22 @@ const findTargetDirectory = function(dir, target) { if (file === target) { return fullPath; } - } - const found = findTargetDirectory(fullPath, target); - if (found) { - return found; + const found = findTargetDirectory(fullPath, target); + if (found) { + return found; + } } } return null; } const getBoardData = function (boardId, itemName) { - const args = ['-g' `${boardId}.${itemName}`] + const args = ['-g', `${boardId}.${itemName}`] let boardData = []; return new Promise((resolve, reject) => { const getCmd = spawn('resource_manager', args); - getCmd.stdout.on('data', (data) => { boardData.push(data.toString()) }); + getCmd.stdout.on('data', (data) => { boardData.push(data.toString().trim()) }); getCmd.stderr.on('data', (data) => { console.log(data.toString()) }); getCmd.on('error', (error) => { console.log(`ERROR: ${error.message}`) }); getCmd.on('close', (code) => { @@ -44,7 +45,7 @@ const getBoardOwner = function (boardId) { let ownerData = [] return new Promise((resolve, reject) => { const getCmd = spawn('resource_manager', args); - getCmd.stdout.on('data', (data) => { ownerData.push(data.toString()) }); + getCmd.stdout.on('data', (data) => { ownerData.push(data.toString().trim()) }); getCmd.stderr.on('data', (data) => { console.log(data.toString()) }); getCmd.on('error', (error) => { console.log(`ERROR: ${error.message}`) }); getCmd.on('close', (code) => { diff --git a/actions/find-board/README.md b/actions/find-board/README.md index fd85177..e65e717 100644 --- a/actions/find-board/README.md +++ b/actions/find-board/README.md @@ -19,9 +19,9 @@ If multiple boards are required with the same criteria, the number of boards can ## Outputs -### board_ids +### board[n] -Space separated list containing the IDs of boards which match the criteria. The action will always return IDs for available boards before returning IDs for boards which are currently in use. +Board matching the given criteria, where `n` is from 1...10 and matches the position of the criteria in the original input. ## Example usage @@ -39,5 +39,11 @@ The output can be accessed via `${{ steps.STEPID.outputs.OUTPUTNAME}}. In this c ```yaml - name: Echo Output - run: echo "Found matching boards --> ${{ steps.findBoards.outputs.board_ids }}" + run: echo "Found matching boards --> ${{ steps.findBoards.outputs.board1 }}, ${{ steps.findBoards.outputs.board2 }}" +``` + +Console output: + +``` +Found matching boards --> max32655_board1, max32655_board2 ``` \ No newline at end of file diff --git a/actions/find-board/action.yml b/actions/find-board/action.yml index e7bef4b..2a87c59 100644 --- a/actions/find-board/action.yml +++ b/actions/find-board/action.yml @@ -1,5 +1,5 @@ name: findBoard -description: 'Find boards matching the given criteria' +description: 'Find boards matching the given criteria. At max 10 boards can be returned at once.' inputs: target: description: 'Desired part number.' @@ -12,8 +12,26 @@ inputs: required: false default: '1' outputs: - board_ids: - description: 'Space separated list of board IDs' + board1: + description: 'Board ID which meets the given criteria.' + board2: + description: 'Board ID which meets the given criteria.' + board3: + description: 'Board ID which meets the given criteria.' + board4: + description: 'Board ID which meets the given criteria.' + board5: + description: 'Board ID which meets the given criteria.' + board6: + description: 'Board ID which meets the given criteria.' + board7: + description: 'Board ID which meets the given criteria.' + board8: + description: 'Board ID which meets the given criteria.' + board9: + description: 'Board ID which meets the given criteria.' + board10: + description: 'Board ID which meets the given criteria.' runs: using: 'node20' main: 'index.js' diff --git a/actions/find-board/index.js b/actions/find-board/index.js index 0d254a4..e872707 100644 --- a/actions/find-board/index.js +++ b/actions/find-board/index.js @@ -19,7 +19,7 @@ const findBoardList = function (target, group) { reject(code); } console.log("Found: %s", foundBoards[0]); - resolve(foundBoards[0]); + resolve(foundBoards[0].trim()); }) }) } @@ -41,32 +41,42 @@ const main = async function() { '!! ERROR: Mismatched parameter lengths. Boards could not be selected. !!' ); } - var retBoards = ''; + let retBoards = []; if (GROUPS.length === 1 && TARGET_NAMES.length === 1) { - let matches = await findBoardList(TARGET_NAMES[0], GROUPS[0]).split(" "); + let matches = await findBoardList(TARGET_NAMES[0], GROUPS[0]); + matches = matches.split(" "); if (matches.length < NUM_BOARDS) { throw new Error('!! ERROR: Not enough matches to fill desired amount of boards. !!'); } for (let i = 0; i < NUM_BOARDS; i++) { - retBoards = `${retBoards} ${matches[i]}`; + retBoards.push(matches[i]); } } else { let matches = []; let valid = []; for (let i = 0; i < GROUPS.length; i++) { - matches[i] = findBoardList(TARGET_NAMES[i], GROUPS[i].split(" ")); + matches[i] = await findBoardList(TARGET_NAMES[i], GROUPS[i]); + matches[i] = matches[i].split(" "); valid[i] = Array(matches[i].length).fill(true); } + console.log(matches) for (let i = 0; i < GROUPS.length; i++) { let match = matches[i][valid[i].indexOf(true)]; for (let j = i+1; j < GROUPS.length; j++) { - if (matches[j].index(match) !== -1) { + if (matches[j].indexOf(match) !== -1) { valid[j][matches[j].indexOf(match)] = false; } } - retBoards = `${retBoards} ${match}`; + retBoards.push(match); + } + } + + for (let i = 0; i < 10; i++) { + if (i >= retBoards.length) { + Core.setOutput(`board${i+1}`, ""); + } else { + Core.setOutput(`board${i+1}`, retBoards[i]); } } - Core.setOutput('board_ids', retBoards.trim()); } main() diff --git a/actions/lock-board/index.js b/actions/lock-board/index.js index 555d96c..35f1edf 100644 --- a/actions/lock-board/index.js +++ b/actions/lock-board/index.js @@ -3,6 +3,7 @@ const Github = require('@actions/github'); const { env } = require('node:process'); const { ALL } = require('node:dns'); +const { spawn } = require('child_process'); const BOARD_IDS = Core.getMultilineInput('boards'); const LOCK_FLAG = Core.getBooleanInput('lock', {required: false}); const TIMEOUT = Core.getInput('timeout', {required: false }); @@ -48,7 +49,7 @@ const unlock = function (boardIds, ownerRef, timeout) { } const unlockOwner = function (ownerRef) { - const args = ['unlock-owner', `${ownerRef}`]; + const args = ['--unlock-owner', `${ownerRef}`]; return new Promise((resolve, reject) => { const cmd = spawn('resource_manager', args); cmd.stdout.on('data', (data) => { console.log(data.toString()) }); diff --git a/actions/make-project/index.js b/actions/make-project/index.js index f271bed..153e9b2 100644 --- a/actions/make-project/index.js +++ b/actions/make-project/index.js @@ -49,7 +49,6 @@ const makeProject = async function (projectPath, distclean, build_flags, board=" { makeArgs.push(`BOARD=${board}`) } - let retVal = 0; await cleanProject(projectPath, distclean, suppress).then( (success) => procSuccess(success, 'Clean'), @@ -59,9 +58,9 @@ const makeProject = async function (projectPath, distclean, build_flags, board=" } ); - let logOut = ''; - let dumpOut = ''; return new Promise((resolve, reject) => { + let logOut = ''; + let dumpOut = ''; if (retVal < 0) { reject(retVal); } diff --git a/actions/ocdflash/action.yml b/actions/ocdflash/action.yml index afe4a69..a851ae7 100644 --- a/actions/ocdflash/action.yml +++ b/actions/ocdflash/action.yml @@ -23,6 +23,9 @@ inputs: description: 'Perform distclean before building? (ignored if build=false)' required: false default: 'false' + owner: + description: "Name of owner of resources" + required: false suppress_output: description: 'Used to suppress console unless an error is encountered.' required: false diff --git a/actions/ocdflash/index.js b/actions/ocdflash/index.js index 3e3f510..8c583f2 100644 --- a/actions/ocdflash/index.js +++ b/actions/ocdflash/index.js @@ -5,6 +5,7 @@ const { spawn } = require('child_process'); const { env } = require('node:process'); const { getBoardData, getBoardOwner, procSuccess, procFail, fileExists, findTargetDirectory } = require('../common'); const { makeProject } = require('../make-project'); +const { Cipher } = require('crypto'); const BOARD_IDS = Core.getMultilineInput('board'); const PROJECT_DIRS = Core.getMultilineInput('project'); @@ -13,7 +14,8 @@ const BUILD_FLAG = Core.getBooleanInput('build', { required: false }); const BUILD_FLAGS = Core.getMultilineInput('build_flags', { required: false }); const DISTCLEAN_FLAG = Core.getBooleanInput('distclean', { required: false }); const SUPPRESS_FLAG = Core.getBooleanInput('suppress_output', { required: false }); -const OWNER_REF = Github.context.ref; +let tmp = Core.getInput('owner', {required: false }); +const OWNER_REF = tmp ? tmp : Github.context.ref; const flashBoard = function (target, elf, dap, gdb, tcl, telnet, suppress) { const args = [ @@ -84,11 +86,7 @@ const main = async function () { getBoardData(BOARD_IDS[i], 'ocdports.gdb'), getBoardData(BOARD_IDS[i], 'ocdports.tcl'), getBoardData(BOARD_IDS[i], 'ocdports.telnet'), - getBoardData(BOARD_IDS[i], 'ocdports.telnet'), - getBoardData(BOARD_IDS[i], 'board'), - - - + getBoardData(BOARD_IDS[i], 'board') ]).catch((err) => console.error(err)); let projPath = findTargetDirectory(path.join(MSDK_PATH, 'Examples', targets[i]), PROJECT_DIRS[i])