Skip to content

Commit

Permalink
Merge pull request #40 from dependabot/feelepxyz/workflow-changes
Browse files Browse the repository at this point in the history
Setup editor integrations and clean up linting
  • Loading branch information
Philip Harrison authored and GitHub committed Jul 21, 2021
2 parents c907920 + 7e9f47c commit 4952b02
Show file tree
Hide file tree
Showing 14 changed files with 1,126 additions and 419 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
charset = utf-8
insert_final_newline = true

[*.json, *.ts]
indent_size = 2
indent_style = space

[*.md]
trim_trailing_whitespace = false
indent_size = 2
10 changes: 4 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"extends": ["plugin:github/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
"project": "./tsconfig.eslint.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"camelcase": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
Expand All @@ -41,8 +41,6 @@
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error",
"@typescript-eslint/no-shadow": "error",
Expand All @@ -53,4 +51,4 @@
"es6": true,
"jest/globals": true
}
}
}
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"EditorConfig.editorconfig",
"Orta.vscode-jest",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "typescript"],
"eslint.alwaysShowStatus": true,
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"editor.formatOnType": false
}
36 changes: 12 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
<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
## Setup

> 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
Install the dependencies

```bash
$ npm install
```

Build the typescript and package it for distribution

```bash
$ npm run build && npm run package
$ npm run package
```

Run the tests :heavy_check_mark:
Run the tests :heavy_check_mark:

```bash
$ npm test

Expand Down Expand Up @@ -57,9 +44,9 @@ import * as core from '@actions/core';
...

async function run() {
try {
try {
...
}
}
catch (error) {
core.setFailed(error.message);
}
Expand All @@ -72,9 +59,10 @@ See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/R

## Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.
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
Expand All @@ -84,7 +72,7 @@ $ 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:
Your action is now published! :rocket:

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

Expand Down
13 changes: 1 addition & 12 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
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('test runs', () => {})
36 changes: 23 additions & 13 deletions __tests__/updater-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,37 @@ describe('Updater', () => {
if (!containers) return

containers.forEach(function (containerInfo) {
if (containerInfo.Image.includes('docker.pkg.github.com/dependabot/dependabot-updater')) {
console.log('removing');
if (
containerInfo.Image.includes(
'docker.pkg.github.com/dependabot/dependabot-updater'
)
) {
console.log('removing')

docker.getContainer(containerInfo.Id).remove();
docker.getContainer(containerInfo.Id).remove()
}
});
});
});
})
})
})

jest.setTimeout(20000)
it('should fetch manifests', async () => {
mockDependabotAPI.getJobDetails.mockImplementation(() => {
return JSON.parse(fs.readFileSync(path.join(__dirname, "fixtures/job-details/npm.json")).toString()).data.attributes
return JSON.parse(
fs
.readFileSync(path.join(__dirname, 'fixtures/job-details/npm.json'))
.toString()
).data.attributes
})
mockDependabotAPI.getCredentials.mockImplementation(() => {
return [{
type: "git_source",
host: "github.com",
username: "x-access-token",
password: process.env.GITHUB_TOKEN,
}]
return [
{
type: 'git_source',
host: 'github.com',
username: 'x-access-token',
password: process.env.GITHUB_TOKEN
}
]
})

await updater.pullImage()
Expand Down
Loading

0 comments on commit 4952b02

Please sign in to comment.