Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
122 lines (114 loc) · 4.86 KB
/
Copy pathaction.yml
File metadata and controls
122 lines (114 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: 'Codeowners Plus'
description: 'Feature-rich alternative to GitHub Code Owners for monoliths and mono-repos'
author: 'Hans Baker'
branding:
icon: 'plus-circle'
color: 'blue'
inputs:
github-token:
description: 'Github API token'
required: true
pr:
description: 'Pull request number'
required: true
repository:
description: 'The owner and repository name. For example `octocat/Hello-World`'
required: true
default: '${{ github.repository }}'
github-api-url:
description: 'GitHub API base URL. Defaults to the API URL of the instance running the workflow. If overriding, use the exact value of the `github.api_url` context (GitHub Enterprise Server includes the /api/v3 suffix; GHE Cloud with data residency does not).'
required: false
default: '${{ github.api_url }}'
verbose:
description: 'Print debug info'
required: false
default: false
quiet:
description: 'Disable PR comments and review requests'
required: false
default: false
outputs:
data:
description: 'JSON string containing all the codeowners data (success, message, file-owners, file-optional, still-required)'
value: ${{ steps.run.outputs.data }}
runs:
using: 'composite'
steps:
- name: 'Resolve codeowners-plus binary'
id: resolve
shell: bash
env:
# The release tag this commit belongs to. Non-empty only in release
# commits: set by scripts/prepare-release.sh and cleared by
# scripts/post-release.sh. When set, the action downloads that
# release's prebuilt binary; when empty (any non-release ref) it
# builds from the checked-out source.
RELEASE_VERSION: ''
run: |
set -euo pipefail
# Normalize GITHUB_ACTION_PATH so `uses: ./` resolves cleanly
ACTION_PATH=$(cd "${GITHUB_ACTION_PATH}" && pwd)
{
echo "release-version=${RELEASE_VERSION}"
echo "bin=${RUNNER_TEMP:-/tmp}/codeowners-plus-action/codeowners-plus"
echo "action-path=${ACTION_PATH}"
} >>"$GITHUB_OUTPUT"
# RELEASE_VERSION not set -> not a release: build from source (cached).
- name: 'Restore cached built binary'
id: buildcache
if: steps.resolve.outputs.release-version == ''
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ steps.resolve.outputs.bin }}
key: codeowners-plus-build-${{ github.action_ref || github.sha }}-${{ runner.os }}-${{ runner.arch }}
- name: 'Set up Go'
if: steps.resolve.outputs.release-version == '' && steps.buildcache.outputs.cache-hit != 'true'
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version-file: ${{ steps.resolve.outputs.action-path }}/go.mod
cache-dependency-path: ${{ steps.resolve.outputs.action-path }}/go.sum
- name: 'Build codeowners-plus from source'
if: steps.resolve.outputs.release-version == '' && steps.buildcache.outputs.cache-hit != 'true'
shell: bash
env:
ACTION_PATH: ${{ steps.resolve.outputs.action-path }}
BIN: ${{ steps.resolve.outputs.bin }}
run: |
set -euo pipefail
mkdir -p "$(dirname "${BIN}")"
cd "${ACTION_PATH}"
CGO_ENABLED=0 \
go build -trimpath -buildvcs=false -ldflags="-s -w" -o "${BIN}" .
# RELEASE_VERSION set -> a release: download + verify the prebuilt binary (cached).
- name: 'Restore cached release binary'
id: bincache
if: steps.resolve.outputs.release-version != ''
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ steps.resolve.outputs.bin }}
key: codeowners-plus-action-${{ steps.resolve.outputs.release-version }}-${{ runner.os }}-${{ runner.arch }}
- name: 'Download codeowners-plus release binary'
if: steps.resolve.outputs.release-version != '' && steps.bincache.outputs.cache-hit != 'true'
shell: bash
env:
REPO: ${{ github.action_repository }}
ACTION_PATH: ${{ steps.resolve.outputs.action-path }}
TAG: ${{ steps.resolve.outputs.release-version }}
BIN: ${{ steps.resolve.outputs.bin }}
run: '"${ACTION_PATH}/scripts/install-action.sh"'
- name: 'Run codeowners-plus'
id: run
shell: bash
env:
# The hyphenated INPUT_GITHUB-TOKEN name is intentional: it mirrors
# what Docker actions export and is exactly what main.go reads via
# os.LookupEnv. Bash passes non-identifier env vars through to child
# processes untouched.
INPUT_GITHUB-TOKEN: ${{ inputs.github-token }}
INPUT_PR: ${{ inputs.pr }}
INPUT_REPOSITORY: ${{ inputs.repository }}
INPUT_GITHUB-API-URL: ${{ inputs.github-api-url }}
INPUT_VERBOSE: ${{ inputs.verbose }}
INPUT_QUIET: ${{ inputs.quiet }}
BIN: ${{ steps.resolve.outputs.bin }}
run: '"${BIN}"'