Skip to content

Commit

Permalink
So many changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Weibye committed Mar 14, 2021
1 parent 52cd480 commit b4b2809
Show file tree
Hide file tree
Showing 114 changed files with 9,701 additions and 53 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -21,4 +21,5 @@ jobs:
- uses: actions/checkout@v2
- uses: ./
with:
milliseconds: 1000
source_path: '__tests__/testData/examples/'
target_paths: '{["__tests__/testData/examples/ios/", "__tests__/testData/examples/excludefolder/"]}'
98 changes: 97 additions & 1 deletion README.md
@@ -1,7 +1,103 @@
<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>
<a href="https://github.com/actions/example_checker/actions"><img alt="example_checker status" src="https://github.com/actions/example_checker/workflows/build-test/badge.svg"></a>
</p>

# Bevy Example checker action

This action parses `./examples/` folders for `example_name.rs` files, and cross references them with both `./examples/README.md` and `./Cargo.toml` to check if they all agree on the same information.

This to prevent people from adding new examples but forgetting to list them in the other sources, or removing examples from documents but forgetting to remove them from the source code.

TODO:
- Make sure all examples are listed in all 3 sources
- readme regex looks for next table and thus loses the last one
- readme must respect exclude directory
- cargo must respect exclude directory
- Cargo should not capture elements that are commented out
- Readme should not capture elements that are commented out

### Requirements / Assumptions

#### Folders
- All examples must reside within the `./examples/` folder
- All example files must have the .rs file ending
-

#### README
- All examples must be listed as entries in a table following the given format:
- All tables must end with an empty new line

```
Example | File | Description
--- | --- | ---
`name_of_example` | [`readme_relative_path_to_file.rs`](./readme/relative/path/to/file.rs) | Text description of the example
```
- The table must have the columns listed as `Example | File | Description`

#### Cargo
- All examples must be listed as entries with the following format
- Must start with the header `[[example]]`
- Must contain `name` and `path` fields
- Example must end with an empty new line
- The block can contain more / other information, which will be ignored by the parser
```
[[example]]
name = "name_of_example"
path = "root/relative/path/to/example"
```


/* Assumptions
* All examples will be within the ./example folder
* All examples are required to be listed in the examples/README.md file
* All example are required to be listed in the Cargo.toml file
* Every single .rs file inside the examples folder represents unique examples
* Only example files will have the .rs file-ending
*
* Potential:
* README
* Check that an entry has description in readme
*
*
* README:
* Assumes 1 empty line between the end of a table and the header of whatever next section

TODO:
- Make sure all examples are listed in all 3 sources
- readme regex looks for next table and thus loses the last one
- readme must respect exclude directory
- cargo must respect exclude directory
- Cargo should not capture elements that are commented out
- Readme should not capture elements that are commented out

<!-- --> comments in readme
# comments in toml


*/

## Inputs

### `who-to-greet`

**Required** The name of the person to greet. Default `"World"`.

## Outputs

### `time`

The time we greeted you.

## Example usage

uses: actions/hello-world-javascript-action@v1.1
with:
who-to-greet: 'Mona the Octocat'


=============================
# Create a JavaScript Action using TypeScript

Use this template to bootstrap the creation of a TypeScript action.:rocket:
Expand Down
38 changes: 23 additions & 15 deletions __tests__/main.test.ts
@@ -1,28 +1,36 @@
import {wait} from '../src/wait'
import { wait } from '../src/wait'
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'

test('throws invalid number', async () => {
const input = parseInt('foo', 10)
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
const input = parseInt('foo', 10)
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
})

test('wait 500 ms', async () => {
const start = new Date()
await wait(500)
const end = new Date()
var delta = Math.abs(end.getTime() - start.getTime())
expect(delta).toBeGreaterThan(450)
const start = new Date()
await wait(500)
const end = new Date()
var delta = Math.abs(end.getTime() - start.getTime())
expect(delta).toBeGreaterThan(450)
})

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_MILLISECONDS'] = '500'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
env: process.env
}
console.log(cp.execFileSync(np, [ip], options).toString())
process.env['INPUT_MILLISECONDS'] = '500'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
env: process.env
}
console.log(cp.execFileSync(np, [ip], options).toString())
})


/*
* Test:
* Faulty example file path
* Faulty cargo file path
* Faulty readme file path
*/

0 comments on commit b4b2809

Please sign in to comment.