Skip to content

Commit

Permalink
added common lib
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmelanchyk committed Nov 1, 2022
1 parent c4a63b7 commit 94496a9
Show file tree
Hide file tree
Showing 42 changed files with 2,304 additions and 933 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
dist/
lib/
node_modules/
jest.config.js
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
dist/** -diff linguist-generated=true
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
open-pull-requests-limit: 0

- package-ecosystem: npm
directory: /
schedule:
Expand Down
14 changes: 3 additions & 11 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/[email protected]
Expand All @@ -34,20 +34,12 @@ jobs:
- name: Rebuild the dist/ directory
run: |
npm run build
npm run package
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
if [ "$(git diff --ignore-space-at-eol lib/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/
id: diff
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
source-root: src
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
name: 'build-test'
on: # rebuild any PRs and main branch changes
on:
pull_request:
workflow_dispatch:
push:
branches:
- main
- 'releases/*'

jobs:
build: # make sure build/ci work properly
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: |
npm install
- run: |
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
milliseconds: 1000
npm run all
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,4 @@ typings/
Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
__tests__/runner/*
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
dist/
lib/
node_modules/
13 changes: 6 additions & 7 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
MIT License

The MIT License (MIT)

Copyright (c) 2018 GitHub, Inc. and contributors
Copyright (c) 2022 Veertu Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -10,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
106 changes: 1 addition & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1 @@
<p align="center">
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
</p>

# Create a JavaScript Action using TypeScript

Use this template to bootstrap the creation of a TypeScript action.:rocket:

This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance.

If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)

## Create an action from this template

Click the `Use this Template` and provide the new repo details for your action

## Code in Main

> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
Install the dependencies
```bash
$ npm install
```

Build the typescript and package it for distribution
```bash
$ npm run build && npm run package
```

Run the tests :heavy_check_mark:
```bash
$ npm test

PASS ./index.test.js
✓ throws invalid number (3ms)
wait 500 ms (504ms)
test runs (95ms)

...
```

## Change action.yml

The action.yml defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)

## Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

```javascript
import * as core from '@actions/core';
...

async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}

run()
```

See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.

## Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run [ncc](https://github.com/zeit/ncc) and push the results:
```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```

Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.

Your action is now published! :rocket:

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)

## Validate

You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))

```yaml
uses: ./
with:
milliseconds: 1000
```
See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
## Usage:
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
# anka-actions-common
47 changes: 47 additions & 0 deletions __tests__/fixtures/list-vm-multiple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"status": "OK",
"message": "",
"body": [
{
"external_id": "0651d321-bf5a-4d8f-b926-1c2cf27744d5",
"instance_id": "cd1937fd-68e7-4d5b-6b75-5ac3260b40f7",
"name": null,
"vm": {
"instance_id": "cd1937fd-68e7-4d5b-6b75-5ac3260b40f7",
"instance_state": "Started",
"anka_registry": "https://18.198.188.108:8089",
"vmid": "4c641deb-9822-4718-a757-5775799d9bc8",
"tag": "latest",
"vminfo": {
"uuid": "bbfa4979-f748-4731-a6f4-4c8d85ec34de",
"name": "mgmtManaged-monterey-1666889320540357000",
"cpu_cores": 2,
"ram": "8G",
"status": "running",
"node_id": "f9673afe-dc07-4683-b625-2bbf9f35f566",
"host_ip": "192.168.1.28",
"ip": "192.168.64.19",
"vnc_port": 0,
"vnc_connection_string": "vnc://:@192.168.1.28:0",
"creation_date": "2022-10-11T10:12:05Z",
"stop_date": "0001-01-01T00:00:00Z",
"version": ""
},
"node_id": "f9673afe-dc07-4683-b625-2bbf9f35f566",
"inflight_reqid": "dc3b8af8-5d14-4ec8-5422-15ebe40ac568",
"ts": "2022-10-27T16:49:35.435875889Z",
"cr_time": "2022-10-27T16:48:39.879143718Z",
"progress": 0,
"external_id": "0651d321-bf5a-4d8f-b926-1c2cf27744d5",
"arch": "arm64",
"vlan": "",
"startup_script": {
"return_code": 0,
"did_timeout": false,
"stdout": "\n--------------------------------------------------------------------------------\n| ____ _ _ _ _ _ _ _ _ |\n| / ___(_) |_| | | |_ _| |__ / \\ ___| |_(_) ___ _ __ ___ |\n| | | _| | __| |_| | | | | '_ \\ / _ \\ / __| __| |/ _ \\| '_ \\/ __| |\n| | |_| | | |_| _ | |_| | |_) | / ___ \\ (__| |_| | (_) | | | \\__ \\ |\n| \\____|_|\\__|_| |_|\\__,_|_.__/ /_/ \\_\\___|\\__|_|\\___/|_| |_|___/ |\n| |\n| Self-hosted runner registration |\n| |\n--------------------------------------------------------------------------------\n\n# Authentication\n\n\n√ Connected to GitHub\n\n# Runner Registration\n\n\n\n\n√ Runner successfully added\n√ Runner connection is good\n\n# Runner settings\n\n\n√ Settings Saved.\n\nCreating launch runner in /Users/anka/Library/LaunchAgents/actions.runner.veertuinc-anka-actions-demo.0651d321-bf5a-4d8f-b926-1c2cf27744d5.plist\nCreating /Users/anka/Library/Logs/actions.runner.veertuinc-anka-actions-demo.0651d321-bf5a-4d8f-b926-1c2cf27744d5\nCreating /Users/anka/Library/LaunchAgents/actions.runner.veertuinc-anka-actions-demo.0651d321-bf5a-4d8f-b926-1c2cf27744d5.plist\nCreating runsvc.sh\nCreating .service\nsvc install complete\nstarting actions.runner.veertuinc-anka-actions-demo.0651d321-bf5a-4d8f-b926-1c2cf27744d5\nstatus actions.runner.veertuinc-anka-actions-demo.0651d321-bf5a-4d8f-b926-1c2cf27744d5:\n\n/Users/anka/Library/LaunchAgents/actions.runner.veertuinc-anka-actions-demo.0651d321-bf5a-4d8f-b926-1c2cf27744d5.plist\n\nStarted:\n592 0 actions.runner.veertuinc-anka-actions-demo.0651d321-bf5a-4d8f-b926-1c2cf27744d5\n\n",
"stderr": ""
}
}
}
]
}
41 changes: 41 additions & 0 deletions __tests__/fixtures/list-vm-single-startup-script-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"status": "OK",
"message": "",
"body": {
"instance_id": "7b3421d9-764c-481c-5e74-8cbd741d3930",
"instance_state": "Error",
"message": "startup script exit code 127",
"anka_registry": "https://19.188.188.108:8089",
"vmid": "4c641deb-9822-4718-a757-5775799d9bc8",
"tag": "latest",
"vminfo": {
"uuid": "2971ce7d-4c76-49eb-8e58-0c75dddd8af3",
"name": "mgmtManaged-monterey-1666774975892452000",
"cpu_cores": 2,
"ram": "8G",
"status": "running",
"node_id": "f9673afe-dc07-4683-b625-2bbf9f35f566",
"host_ip": "192.168.1.28",
"ip": "192.168.64.3",
"vnc_port": 0,
"vnc_connection_string": "vnc://:@192.168.1.28:0",
"creation_date": "2022-10-11T10:12:05Z",
"stop_date": "0001-01-01T00:00:00Z",
"version": ""
},
"node_id": "f9673afe-dc07-4683-b625-2bbf9f35f566",
"inflight_reqid": "3b6435cb-37d1-4401-7dcd-b78cf181917d",
"ts": "2022-10-26T09:03:24.141596234Z",
"cr_time": "2022-10-26T09:02:44.646758236Z",
"progress": 1,
"external_id": "f3015250-99fb-415b-a8ee-5c16f3e58514",
"arch": "arm64",
"vlan": "",
"startup_script": {
"return_code": 127,
"did_timeout": false,
"stdout": "",
"stderr": "sh: line 1: asdadfasdflakdsmnflaksdnfaklsdnf!@#$: command not found\n"
}
}
}
18 changes: 18 additions & 0 deletions __tests__/fixtures/list-vm-single-state-scheduling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"status": "OK",
"message": "",
"body": {
"instance_id": "7b3421d9-764c-481c-5e74-8cbd741d3930",
"instance_state": "Scheduling",
"anka_registry": "https://19.188.188.108:8089",
"vmid": "4c641deb-9822-4718-a757-5775799d9bc8",
"tag": "latest",
"inflight_reqid": "3b6435cb-37d1-4401-7dcd-b78cf181917d",
"ts": "2022-10-26T09:02:44.646756913Z",
"cr_time": "2022-10-26T09:02:44.646758236Z",
"progress": 0,
"external_id": "f3015250-99fb-415b-a8ee-5c16f3e58514",
"arch": "arm64",
"vlan": ""
}
}
4 changes: 4 additions & 0 deletions __tests__/fixtures/start-vm-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": "FAIL",
"message": "VM not in the registry"
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/start-vm-ok.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"status": "OK",
"message": "",
"body": [
"b7fed205-ceab-4938-60cd-1369a3cc0d4f"
]
}
4 changes: 4 additions & 0 deletions __tests__/fixtures/terminate-vm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"status": "OK",
"message": ""
}
Loading

0 comments on commit 94496a9

Please sign in to comment.