-
Notifications
You must be signed in to change notification settings - Fork 3
99 lines (96 loc) · 3.67 KB
/
generate.yml
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
name: Generate
on:
pull_request:
branches: ['**']
merge_group:
branches: ['main']
push:
branches: ['main']
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
generate:
runs-on: ubuntu-latest
outputs:
has-patch: ${{ steps.is-tree-dirty.outputs.result }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 'stable'
cache-dependency-path: '**/*.sum'
- name: Run 'go generate ./...'
run: |-
mkdir -p ${GOCOVERDIR}
go generate ./...
env:
GOFLAGS: -covermode=atomic -coverpkg=github.com/datadog/orchestrion/...
GOCOVERDIR: ${{ github.workspace }}/coverage
- name: Consolidate coverage report
if: always() && github.event_name != 'merge_group'
run: go tool covdata textfmt -i ./coverage -o ./coverage/generator.out
- name: Upload coverage report
# We want this even if the tests failed
if: always() && github.event_name != 'merge_group'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: ${{ runner.os }},${{ runner.arch }},generator
file: ./coverage/generator.out
name: Generators
- name: Run 'go mod tidy'
# Don't run for push, it's not necessary
if: github.event_name != 'push'
run: find . -iname go.mod -execdir go mod tidy \;
- name: Check if working tree is dirty
# Don't run for push, it's not necessary
if: github.event_name != 'push'
id: is-tree-dirty
run: |-
git add .
git diff --staged --patch --exit-code > .repo.patch || echo "result=true" >> ${GITHUB_OUTPUT}
- name: Upload patch
if: github.event_name != 'push' && steps.is-tree-dirty.outputs.result == 'true'
uses: actions/upload-artifact@v4
with:
name: repo.patch
path: .repo.patch
- name: Fail build if working tree is dirty
if: github.event_name == 'push' && steps.is-tree-dirty.outputs.result == 'true'
run: |-
echo "::error::Files have been modified by 'go generate ./...' (see logs)."
cat .repo.patch
exit 1
# If generated files changed and this is a pull request that we can modify, update the PR with the updated files.
self-mutation:
needs: generate
runs-on: ubuntu-latest
if: always() && needs.generate.outputs.has-patch == 'true' && github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name == github.repository || github.event.pull_request.maintainer_can_modify)
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Download patch
uses: actions/download-artifact@v4
with:
name: repo.patch
path: ${{ runner.temp }}
- name: Apply patch
run: |-
[ -s '${{ runner.temp }}/.repo.patch' ] && git apply '${{ runner.temp }}/.repo.patch' || echo 'Empty patch. Skipping.'
- name: Setup git identity
run: |-
git config user.name "github-actions on behalf of ${{ github.actor }}"
git config user.email "github-actions@github.com"
- name: Push changes
run: |-
git add .
git commit -s -m "chore: update generated files"
git push origin HEAD:${{ github.event.pull_request.head.ref }}