forked from microsoft/typescript-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
170 lines (146 loc) · 5.6 KB
/
action.yml
File metadata and controls
170 lines (146 loc) · 5.6 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Setup Go
description: Setup Go
inputs:
go-version:
description: Go version to set up in go-install.ps1 format
default: 'go1.25'
create:
description: Create the cache
default: 'false'
lint-cache:
description: Restore the golangci-lint cache
default: 'false'
runs:
using: composite
steps:
- name: Install Go
id: install-go
shell: pwsh
run: |
# https://github.com/microsoft/go-infra/blob/main/goinstallscript/powershell/go-install.ps1
${{ github.action_path }}/go-install.ps1 -Version ${{ inputs.go-version }} -GitHubActionsPath
$goVersionOutput = go version
Write-Host $goVersionOutput
# Extract version like "1.23.4" from "go version go1.23.4 windows/amd64"
if ($goVersionOutput -match 'go version go([\d\.]+)') {
$exactVersion = $matches[1]
"go-version=$exactVersion" >> $env:GITHUB_OUTPUT
Write-Host "Exact Go version: $exactVersion"
} else {
Write-Error "Failed to parse Go version from: $goVersionOutput"
exit 1
}
- name: Verify Microsoft Go
shell: pwsh
run: |
$goPath = (Get-Command go).Source
Write-Host "Go executable path: $goPath"
if ($goPath -notlike "*microsoft-go*") {
Write-Error "Go installation is not from microsoft-go. Path: $goPath"
exit 1
}
Write-Host "✓ Verified: Microsoft Go is active"
- name: Add GOBIN to PATH
shell: bash
run: |
GOBIN=$(go env GOBIN)
if [ -z "$GOBIN" ]; then
GOBIN="$(go env GOPATH)/bin"
fi
echo "$GOBIN" >> $GITHUB_PATH
# Avoid hardcoding the cache keys more than once.
- name: Get cache info
shell: bash
id: cache-info
env:
MODULES_KEY: go-modules-${{ runner.os }}-msft-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/.custom-gcl.yml') }}
LINT_KEY: golangci-lint-${{ runner.os }}-msft-${{ steps.install-go.outputs.go-version }}-${{ hashFiles('**/go.sum', '**/.custom-gcl.yml') }}
BUILD_KEY: go-build-cache-${{ runner.os }}-msft-${{ steps.install-go.outputs.go-version }}
run: |
echo "modules-key=$MODULES_KEY" >> $GITHUB_OUTPUT
echo "lint-key=$LINT_KEY" >> $GITHUB_OUTPUT
echo "build-key=$BUILD_KEY" >> $GITHUB_OUTPUT
echo "GOLANGCI_LINT_CACHE=$RUNNER_TEMP/golangci-lint-cache" >> $GITHUB_ENV
- if: ${{ inputs.create != 'true' }}
name: Restore Go modules
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
key: ${{ steps.cache-info.outputs.modules-key }}
path: |
~/go/pkg/mod
- if: ${{ inputs.create != 'true' }}
name: Restore Go build cache
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
key: unused-key-${{ github.run_id }}
restore-keys: ${{ steps.cache-info.outputs.build-key }}-
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build
- if: ${{ inputs.create != 'true' && inputs.lint-cache == 'true' }}
name: Restore golangci-lint cache
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
key: unused-key-${{ github.run_id }}
restore-keys: ${{ steps.cache-info.outputs.lint-key }}-
path: ${{ env.GOLANGCI_LINT_CACHE }}
- name: Set mtimes
shell: bash
run: |
find . -type f ! -path ./.git/\*\* | go run github.com/slsyy/mtimehash/cmd/mtimehash@v1.0.0 || true
find . -type d ! -path ./.git/\*\* -exec touch -d '1970-01-01T00:00:01Z' {} + || true
# All steps below are only run if the cache is being created.
- if: ${{ inputs.create == 'true' }}
shell: bash
run: npm ci
- if: ${{ inputs.create == 'true' }}
shell: bash
run: |
go mod download
cd _tools
go mod download
- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby build
- if: ${{ inputs.create == 'true' }}
shell: bash
id: setup-go-test
run: npx hereby test
- if: ${{ failure() && inputs.create == 'true' && steps.setup-go-test.conclusion == 'failure' }}
shell: bash
run: git diff --diff-filter=AM --no-index ./testdata/baselines/reference ./testdata/baselines/local
- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby test --coverage
- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby lint
- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx hereby lint --noembed
- if: ${{ inputs.create == 'true' }}
shell: bash
run: npx dprint check
- if: ${{ inputs.create == 'true' }}
name: Save Go modules
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
key: ${{ steps.cache-info.outputs.modules-key }}
path: |
~/go/pkg/mod
- if: ${{ inputs.create == 'true' }}
name: Save Go build cache
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
key: ${{ steps.cache-info.outputs.build-key }}-${{ github.run_id }}
path: |
~/.cache/go-build
~/Library/Caches/go-build
~/AppData/Local/go-build
- if: ${{ inputs.create == 'true' }}
name: Save golangci-lint cache
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
key: ${{ steps.cache-info.outputs.lint-key }}-${{ github.run_id }}
path: ${{ env.GOLANGCI_LINT_CACHE }}