Skip to content

Instantly share code, notes, and snippets.

@KisaragiEffective
Created June 14, 2020 06:26
Show Gist options
  • Save KisaragiEffective/1313afd5f9ef4e088817dc9f0f1b6933 to your computer and use it in GitHub Desktop.
Save KisaragiEffective/1313afd5f9ef4e088817dc9f0f1b6933 to your computer and use it in GitHub Desktop.
GitHubActionsのjson型定義を書くのが面倒だったからTypeScriptで定義してみたら思ったよりも簡単に定義できた
/*
Copyright 2020 KisaragiEffective
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights 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 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.
*/
type Support = "windows-latest" | "windows-2019" | "ubuntu-latest" | "ubuntu-18.04" | "ubuntu-16.04" | "macos-latest" | "macos-10.15" | "self-hosted"
type Action = keyof TriggerSpec
type Defaults = {
defaults: {
run: {}
}
}
type GitHubActions = {
name?: string
on: Action | Action[] | TriggerSpec
jobs: JobConfiguration[]
} & Partial<Envilonment> & Partial<Defaults> & Partial<Conditional>
type MapType<K, V> = {[key: K]: V}
type Envilonment = {env: {[key: string]: number | string}}
type Conditional = {
if: string
}
type Timeout = {
"timeout-minutes": number
}
type JobConfiguration = {
name: string
"runs-on": Support
steps: Step[]
needs?: string[]
outputs?: {[key: string]: string}
//
strategy?: {
matrix: {
os: Support[]
[key: string]: any
include?: {
os: Support
[key: string]: any
}[]
exclude?: {
os: Support
[key: string]: any
}
}
"fail-fast"?: boolean
"max-parallel"?: number
"continue-on-error"?: boolean
}
container?: ({
image: string
ports: number[]
volumes?: string[]
options?: string
} & Partial<Envilonment>) | string
services: {
[name: string]: {
image: string
ports: string[]
volumes?: string[]
options?: string
} & Partial<Envilonment>
}
} & Partial<Envilonment> & Partial<Defaults> & Partial<Conditional> & Partial<Timeout>
type Step = {
name: string
uses?: string
with?: {[key: string]: (string | boolean | number)} & {entrypoint: string}
run?: string
"working-directory"?: string
shell?: "bash" | "pwsh" | "python" | "sh" | "cmd" | "powershell"
"continue-on-error"?: boolean
} & Partial<Envilonment> & Partial<Timeout>
type UniqueArray<T extends (string | number)> = Array<T>
type BranchTagSpec = Partial<{branches: string[]} | {"branches-ignore": string[]}> & Partial<{tags: string[]} | {"tags-ignore": string[]}>
type PathSpec = Partial<{paths: string[]} | {"paths-ignore": string[]}>
type TriggerSpec = {
check_run?: {
types: UniqueArray<"created" | "rerequested" | "completed" | "requested_action">
}
check_suite?: {
types: UniqueArray<"completed" | "requested" | "rerequested">
}
create?: {}
delete?: {}
deployment?: {}
deployment_status?: {}
fork?: {}
// someone has just updated wiki
gollum?: {}
issue_comment?: {
types: UniqueArray<"created" | "edited" | "deleted">
}
issues?: {
types: UniqueArray<"opened" | "edited" | "deleted" | "transferred" | "pinned" | "unpinned" | "closed" | "reopened" | "assigned" | "unassigned" | "labeled" | "unlabeled" | "locked" | "unlocked" | "milestoned" | "demilestoned">
}
label?: {
types: UniqueArray<"created" | "edited" | "deleted">
}
milestone?: {
types: UniqueArray<"created" | "closed" | "opened" | "edited" | "deleted">
}
page_build?: {}
project?: {
types: UniqueArray<"created" | "updated" | "closed" | "reopened" | "edited" | "deleted">
}
project_card?: {
types: UniqueArray<"created" | "moved" | "converted" | "edited" | "deleted">
}
project_column?: {
types: UniqueArray<"created" | "updated" | "moved" | "deleted">
}
public?: {}
pull_request?: {
types: UniqueArray<"assigned" | "unassigned" | "labeled" | "unlabeled" | "opened" | "edited" | "closed" | "reopened" | "synchronize" | "ready_for_review" | "locked" | "unlocked" | "review_requested" | "review_request_removed">
} & BranchTagSpec & PathSpec
pull_request_review?: {
types: UniqueArray<"submitted" | "edited" | "dismissed">
}
pull_request_review_comment?: {
types: UniqueArray<"created" | "edited" | "deleted">
}
push?: BranchTagSpec & PathSpec
registry_package?: {
types: UniqueArray<"published" | "updated">
}
release?: {
types: UniqueArray<"published" | "unpublished" | "created" | "edited" | "deleted" | "prereleased" | "released">
}
status?: {}
watch?: {
types: UniqueArray<"started">
}
schedule?: {
cron: string
}[]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment