Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Jun 16, 2020
2 parents 54225e9 + cc5d265 commit b99689c
Show file tree
Hide file tree
Showing 10 changed files with 9,177 additions and 108 deletions.
92 changes: 55 additions & 37 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
host-pre-commands: "env"
anka-template: "10.15.4"
anka-tag: "base:port-forward-22:brew-git:openjdk-1.8.0_242:jenkins"
anka-tag: "base:port-forward-22:brew-git:openjdk-1.8.0_242"
commands: "echo 123"

- name: basic commands
Expand All @@ -39,6 +39,7 @@ jobs:
with:
anka-template: "10.15.4"
anka-tag: "base:port-forward-22:brew-git"
host-post-commands: "env"
commands: |
env
ls -laht ./
Expand Down Expand Up @@ -78,7 +79,7 @@ jobs:
pwd
echo "HERE" && \
echo "THERE HERE WHERE"
host-pre-commands: "echo PRE COMMANDS"
host-pre-commands: "env && echo PRE COMMANDS"
host-post-commands: "echo POST COMMANDS && echo \"CWD: $(pwd)\""
anka-start-options: "-f"
anka-run-options: "--workdir /tmp"
Expand All @@ -102,8 +103,7 @@ jobs:
pwd > test1
echo "HERE" && \
echo "THERE HERE WHERE"
host-pre-commands: "echo PRE COMMANDS"
host-post-commands: "echo POST COMMANDS && echo \"CWD: $(pwd)\""
host-post-commands: "env && echo POST COMMANDS && echo \"CWD: $(pwd)\""
anka-start-options: "-f"
artifact-archive-file-name: "test-artifact"
artifact-files: |
Expand All @@ -113,48 +113,66 @@ jobs:
test3
# [[ ]] testing doesn't like when you interpolate a multi-line ${{ steps. . . }} right in the -z ""; set it to a variable first, then test a single line
# Must single quote output in run: due to quotes in commands: (basic)
- name: Check for output (testing anything execute.test.js doesn't)
run: |
BASIC_STD="${{ steps.basic.outputs.std }}"
printf "basic std ========================\n${{ steps.basic.outputs.std }}"
[[ ! -z "$(echo $BASIC_STD | head -n 1)" ]] || exit 10
[[ -z "$(echo $BASIC_STD | grep 'jenkins')" ]] || exit 11
[[ ! -z "$(echo $BASIC_STD | grep '(base:port-forward-22:brew-git)')" ]] || exit 12
CHAINED_REDIRECT_STD="${{ steps.chained-redirect.outputs.std }}"
printf "\nchained-redirect stdout ========================\n${{ steps.chained-redirect.outputs.std }}"
[[ ! -z "$(echo $CHAINED_REDIRECT_STD | head -n 1)" ]] || exit 20
SCRIPT_AND_ARGS_STD="${{ steps.script-and-args.outputs.std }}"
printf "\nscript-and-args stdout ========================\n${{ steps.script-and-args.outputs.std }}"
[[ ! -z "$(echo $SCRIPT_AND_ARGS_STD | head -n 1)" ]] || exit 30
[[ ! -z "$(echo $SCRIPT_AND_ARGS_STD | grep '| 10.15.4 (base)')" ]] || exit 31
INPUTS_TESTING_STD="${{ steps.inputs-testing.outputs.std }}"
printf "\ninputs-testing stdout ========================\n${{ steps.inputs-testing.outputs.std }}"
[[ ! -z "$(echo $INPUTS_TESTING_STD | head -n 1)" ]] || exit 40
[[ ! -z "$(echo $INPUTS_TESTING_STD | grep 'PRE COMMANDS')" ]] || exit 41
[[ ! -z "$(echo $INPUTS_TESTING_STD | grep 'POST COMMANDS')" ]] || exit 42
[[ ! -z "$(echo $INPUTS_TESTING_STD | grep '| custom-label-')" ]] || exit 43
[[ ! -z "$(echo $INPUTS_TESTING_STD | grep 'CWD: /private/tmp')" ]] || exit 44
[[ ! -z "$(echo $INPUTS_TESTING_STD | grep 'PWD=/private/tmp')" ]] || exit 45
PULL_TEST_PREP_TWO_STD='${{ steps.pull-test-prep-2.outputs.std }}'
printf "\n=======================\npull-test-prep-2 std\n========================\n$PULL_TEST_PREP_TWO_STD"
[[ ! -z "$(echo \"$PULL_TEST_PREP_TWO_STD\" | head -n 1)" ]] || exit 1
[[ ! -z "$(echo \"$PULL_TEST_PREP_TWO_STD\" | grep '(base:port-forward-22:brew-git:openjdk-1.8.0_242)')" ]] || exit 3
[[ ! -z "$(echo \"$PULL_TEST_PREP_TWO_STD\" | grep 'self1_isPost=true')" ]] || exit 4
[[ -z "$(echo \"$PULL_TEST_PREP_TWO_STD\" | grep 'self1_isCreated')" ]] || exit 5
[[ -z "$(echo \"$PULL_TEST_PREP_TWO_STD\" | grep 'self1_isLocked')" ]] || exit 6
BASIC_STD='${{ steps.basic.outputs.std }}'
printf "\n=======================\nbasic std\n========================\n$BASIC_STD"
[[ ! -z "$(echo \"$BASIC_STD\" | head -n 1)" ]] || exit 10
[[ -z "$(echo \"$BASIC_STD\" | grep 'base:port-forward-22:brew-git:openjdk-')" ]] || exit 11
[[ ! -z "$(echo \"$BASIC_STD\" | grep '(base:port-forward-22:brew-git)')" ]] || exit 12
[[ ! -z "$(echo \"$BASIC_STD\" | grep 'self2_isPost=true')" ]] || exit 13
[[ ! -z "$(echo \"$BASIC_STD\"| grep 'self2_isCreated=true')" ]] || exit 14
[[ ! -z "$(echo \"$BASIC_STD\" | grep 'self2_isLocked=false')" ]] || exit 15
CHAINED_REDIRECT_STD='${{ steps.chained-redirect.outputs.std }}'
printf "\n=======================\nchained-redirect stdout\n========================\n$CHAINED_REDIRECT_STD"
[[ ! -z "$(echo \"$CHAINED_REDIRECT_STD\" | head -n 1)" ]] || exit 20

SCRIPT_AND_ARGS_STD='${{ steps.script-and-args.outputs.std }}'
printf "\n=======================\nscript-and-args stdout\n========================\n$SCRIPT_AND_ARGS_STD"
[[ ! -z "$(echo \"$SCRIPT_AND_ARGS_STD\" | head -n 1)" ]] || exit 30
[[ ! -z "$(echo \"$SCRIPT_AND_ARGS_STD\" | grep '| 10.15.4 (base)')" ]] || exit 31

INPUTS_TESTING_STD='${{ steps.inputs-testing.outputs.std }}'
printf "\n=======================\ninputs-testing stdout\n========================\n$INPUTS_TESTING_STD"
[[ ! -z "$(echo \"$INPUTS_TESTING_STD\" | head -n 1)" ]] || exit 40
[[ ! -z "$(echo \"$INPUTS_TESTING_STD\" | grep 'PRE COMMANDS')" ]] || exit 41
[[ ! -z "$(echo \"$INPUTS_TESTING_STD\" | grep 'POST COMMANDS')" ]] || exit 42
[[ ! -z "$(echo \"$INPUTS_TESTING_STD\" | grep '| custom-label-')" ]] || exit 43
[[ ! -z "$(echo \"$INPUTS_TESTING_STD\" | grep 'CWD: /private/tmp')" ]] || exit 44
[[ ! -z "$(echo \"$INPUTS_TESTING_STD\" | grep 'PWD=/private/tmp')" ]] || exit 45
[[ ! -z "$(echo \"$INPUTS_TESTING_STD\" | grep 'self5_isPost=true')" ]] || exit 46
[[ -z "$(echo \"$INPUTS_TESTING_STD\" | grep 'self5_isCreated')" ]] || exit 47
[[ -z "$(echo \"$INPUTS_TESTING_STD\" | grep 'self5_isLocked')" ]] || exit 48

ARTIFACTS_ONE_STD='${{ steps.artifacts-1.outputs.std }}'
printf "\n=======================\nartifacts-1 stdout\n========================\n$ARTIFACTS_ONE_STD"
[[ ! -z "$(echo \"$ARTIFACTS_ONE_STD\" | head -n 1)" ]] || exit 50
[[ ! -z "$(echo \"$ARTIFACTS_ONE_STD\" | grep 'Created and uploaded artifact test-artifact')" ]] || exit 51
[[ ! -z "$(echo \"$ARTIFACTS_ONE_STD\" | grep 'Archive contents:.*/test1.*/test2.*/test3')" ]] || exit 52
[[ ! -z "$(echo \"$ARTIFACTS_ONE_STD\" | grep 'self6_isPost=true')" ]] || exit 53
[[ ! -z "$(echo \"$ARTIFACTS_ONE_STD\" | grep 'self6_isCreated=true')" ]] || exit 54
[[ ! -z "$(echo \"$ARTIFACTS_ONE_STD\" | grep 'self6_isLocked=false')" ]] || exit 55

ARTIFACTS_ONE_STD="${{ steps.artifacts-1.outputs.std }}"
printf "\nartifacts-1 stdout ========================\n${{ steps.artifacts-1.outputs.std }}"
[[ ! -z "$(echo $ARTIFACTS_ONE_STD | head -n 1)" ]] || exit 50
[[ ! -z "$(echo $ARTIFACTS_ONE_STD | grep 'Created and uploaded artifact test-artifact')" ]] || exit 51
[[ ! -z "$(echo $ARTIFACTS_ONE_STD | grep 'Archive contents:.*/test1.*/test2.*/test3')" ]] || exit 52
true

functional-tests-second-agent:
runs-on: [self-hosted, macOS]
needs: prep
steps:
- uses: actions/checkout@v2
- name: sleep
run: "sleep 20"
run: "sleep 30"
- name: pull test 2
id: pull-test-2
uses: ./
Expand All @@ -171,8 +189,8 @@ jobs:
- name: Check for output (testing anything execute.test.js doesn't)
run: |
PULL_TEST_STD="${{ steps.pull-test-2.outputs.std }}"
printf "pull test std ========================\n${{ steps.pull-test-2.outputs.std }}"
PULL_TEST_STD='${{ steps.pull-test-2.outputs.std }}'
printf "\n=======================\npull test std\n========================\n${{ steps.pull-test-2.outputs.std }}"
[[ ! -z "$(echo $PULL_TEST_STD | head -n 1)" ]] || exit 100
[[ ! -z "$(echo $PULL_TEST_STD | grep 'Lock file /tmp/registry-pull-lock-10.15.4 found')" ]] || exit 101
Expand Down
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ jobs:
anka-template: "10.15.4"
anka-tag: "base:port-forward-22:xcode11-v1"
commands: |
git clone https://github.com/aws0m0rg/my-awesome-ios-project.git && \
cd my-awesome-ios-project
./build.sh
echo "Starting build process"
./build.sh && \
./cleanup.sh
artifacts: |
log.txt
build/binaryfile-v1
```
The above example will clone your project repo to the github action runner's working directory, pull the Template `10.15.4` and Tag `base:port-forward-22:xcode11-v1` from the Registry, prepare an Anka VM using that Template and Tag, execute the commands inside of the VM, and then upload artifacts `./log.txt` and `./build/binaryfile-v1` from the current directory (which is mounted by default into the VM).

> **Build and Test time can be significantly impacted by the default host -> guest mount. It's suggested that you use `anka-run-options: "--wait-network --wait-time --no-volume"` and then git clone your repo inside of `commands:`.**

### Inputs

These are defined under the `with:` mapping key inside of your workflow yaml.

#### `anka-template`:
#### `anka-template`

- **Name or UUID of your Anka Template**
- **[Required]**
Expand All @@ -48,13 +50,13 @@ These are defined under the `with:` mapping key inside of your workflow yaml.
- **[Required]**
- You can use `commands: |` for multi-line input or a simple string
#### `anka-tag`:
#### `anka-tag`

- **Name of Anka Tag (optional)**
- defaults to latest tag

#### `anka-custom-vm-label`: label for the cloned VM that will execute your code

#### `anka-custom-vm-label`
- **Label for the cloned VM that will execute your code**
- Defaults to `github-actions-${GITHUB_REPOSITORY}-${GITHUB_RUN_NUMBER}-${GITHUB_JOB}-${GITHUB_ACTION}`
- Your custom label will have a random number added to the end of it to prevent collisions when two VMs are running on the same node with the same label

Expand Down Expand Up @@ -90,8 +92,8 @@ These are defined under the `with:` mapping key inside of your workflow yaml.

These are returned to your workflow.yaml so that subsequent steps can use them.

#### `std`: the STDOUT and STDERR from the executed commands

#### `std`
- The STDOUT and STDERR from the executed commands
- Includes artifact upload output

Usage:
Expand Down Expand Up @@ -121,9 +123,9 @@ Usage:
- name: Check for output
run: |
PULL_TEST_STD="${{ steps.pull-test-2.outputs.std }}"
printf "pull test std ========================\n${{ steps.pull-test-2.outputs.std }}"
[[ ! -z "$(echo $PULL_TEST_STD | head -n 1)" ]] || exit 50
[[ ! -z "$(echo $PULL_TEST_STD | grep 'Lock file /tmp/registry-pull-lock-10.15.4 found')" ]] || exit 51
printf "pull test std ========================\n$PULL_TEST_STD"
[[ ! -z "$(echo \"$PULL_TEST_STD\" | head -n 1)" ]] || exit 50
[[ ! -z "$(echo \"$PULL_TEST_STD\" | grep 'Lock file /tmp/registry-pull-lock-10.15.4 found')" ]] || exit 51
true
```

Expand All @@ -148,14 +150,8 @@ There are two types of tests we perform:
2. Functional testing using a workflow yaml (not in this repo)

### TO-DO
<<<<<<< HEAD
- Support cleanup on cancellation (are hooks even possible with actions?)
- Support multiple artifacts and files for those artifacts
- Better tests with mocks so we can avoid so much functional testing
=======
- Support cleanup on cancellation (are hooks even possible with actions?) (javascript to catch signals)
- Support multiple artifacts and files for those artifacts
- Better tests with mocks so we can avoid so much functional testing
- Execution of anka run should happen with `anka run template sh` and then passing into STDIN
- Passing host ENV into VM
- Clone within VM (with skip-clone inputs)
- Clone within VM (with skip-clone inputs)
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ outputs:
runs:
using: 'node12'
main: 'dist/index.js'
post: 'dist/index.js'

9,003 changes: 9,002 additions & 1 deletion dist/index.js

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions helpers.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
const core = require('@actions/core');
const execute = require('./execute');
const prepare = require('./prepare');

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
module.exports.sleep = sleep;

async function getVMLabel(ankaCustomVMLabel) {
if (process.env[`${process.env['GITHUB_ACTION']}_vmLabel`] !== undefined) { // return the existing VM's label
return process.env[`${process.env['GITHUB_ACTION']}_vmLabel`]
}
if (typeof(ankaCustomVMLabel) === "undefined" || ankaCustomVMLabel.length === 0) {
return `github-actions-\${GITHUB_REPOSITORY}-\${GITHUB_RUN_NUMBER}-\${GITHUB_JOB}-\${GITHUB_ACTION}`
var vmLabel = `github-actions-${process.env['GITHUB_REPOSITORY']}-${process.env['GITHUB_RUN_NUMBER']}-${process.env['GITHUB_JOB']}-${process.env['GITHUB_ACTION']}`
} else {
// Needs a random number to prevent collision (we use GITHUB_RUN_NUMBER and GITHUB_ACTION for this if user doesn't specify a label); might be removed in later versions
return `${ankaCustomVMLabel}-${Math.floor(Math.random() * 9999) + 1}`
var vmLabel = `${ankaCustomVMLabel}-${Math.floor(Math.random() * 9999) + 1}`
}
core.exportVariable(`${process.env['GITHUB_ACTION']}_vmLabel`, vmLabel);
return vmLabel
}
module.exports.getVMLabel = getVMLabel;

Expand Down Expand Up @@ -45,3 +54,17 @@ async function turnStringIntoObject(hostCommandOptions,options) {
return options
}
module.exports.turnStringIntoObject = turnStringIntoObject;


async function cleanup(ankaCustomVMLabel,hostCommandOptions,ankaTemplate,lockFileLocation) {
try {
if (process.env[`${process.env['GITHUB_ACTION']}_isCreated`] === 'true') { // Prevent the delete if the VM was never created
await execute.nodeCommands(`anka delete --yes ${await getVMLabel(ankaCustomVMLabel)}`,await turnStringIntoObject(hostCommandOptions,{ silent: false }),execute.STD)
core.exportVariable(`${process.env['GITHUB_ACTION']}_isCreated`, false);
}
await prepare.deleteLockFile(ankaTemplate,lockFileLocation)
} catch (error) {
throw new Error(`Cleanup failed:\n${error.stack}`);
}
}
module.exports.cleanup = cleanup;
19 changes: 18 additions & 1 deletion helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
let helpers = require('./helpers');
const core = require('@actions/core');

describe('helper functions', () => {
describe('getVMLabel', () => {
afterEach(() => {
core.exportVariable('GITHUB_REPOSITORY', undefined)
core.exportVariable('GITHUB_RUN_NUMBER', undefined);
core.exportVariable('GITHUB_JOB', undefined);
core.exportVariable('GITHUB_ACTION', undefined);
});
test('default (no argument)', async() => {
expect(await helpers.getVMLabel()).toBe('github-actions-\${GITHUB_REPOSITORY}-\${GITHUB_RUN_NUMBER}-\${GITHUB_JOB}-\${GITHUB_ACTION}')
core.exportVariable('GITHUB_REPOSITORY', 'veertuinc/anka-vm-github-action');
core.exportVariable('GITHUB_RUN_NUMBER', '102');
core.exportVariable('GITHUB_JOB', 'functional-tests');
core.exportVariable('GITHUB_ACTION', 'self2');
expect(await helpers.getVMLabel()).toBe('github-actions-veertuinc/anka-vm-github-action-102-functional-tests-self2')
expect(process.env["self2_vmLabel"]).toBe('github-actions-veertuinc/anka-vm-github-action-102-functional-tests-self2')
}); // TEST
test('custom', async() => {
core.exportVariable('GITHUB_REPOSITORY', 'veertuinc/anka-vm-github-action');
core.exportVariable('GITHUB_RUN_NUMBER', '102');
core.exportVariable('GITHUB_JOB', 'functional-tests');
core.exportVariable('GITHUB_ACTION', 'self3');
expect(await helpers.getVMLabel("build-vms")).toMatch(/build-vms-\d+/)
expect(process.env["self3_vmLabel"]).toMatch(/build-vms-\d+/)
}); // TEST
}); // DESCRIBE
describe('turnStringIntoObject', () => {
Expand Down
Loading

0 comments on commit b99689c

Please sign in to comment.