-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (145 loc) · 5.28 KB
/
pr.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
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
name: pr
on:
pull_request: {}
jobs:
tagfile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # For $ git tag
- name: Ensure Tagfile is usable
run: grep -E '^[0-9]+[.][0-9]+[.][0-9]+$' Tagfile
- name: Checkout master Tagfile
uses: actions/checkout@v3
with:
ref: master
path: ./master-Tagfile
- name: Ensure Tagfile has changes
run: '! diff -q Tagfile ./master-Tagfile/Tagfile'
- name: Ensure tag wasn't published already
run: git tag | grep -vF $(cat Tagfile)
- name: Ensure new tag is a 1-increment
run: |
curr=$(cat Tagfile)
prev=./master-Tagfile/Tagfile
{
echo $(( $(cut -d. -f1 <$prev) + 1 )).$(cut -d. -f2 <$prev).$(cut -d. -f3 <$prev)
echo $(cut -d. -f1 <$prev).$(( $(cut -d. -f2 <$prev) + 1 )).$(cut -d. -f3 <$prev)
echo $(cut -d. -f1 <$prev).$(( $(cut -d. -f2 <$prev) + 1 )).0
echo $(cut -d. -f1 <$prev).$(cut -d. -f2 <$prev).$(( $(cut -d. -f3 <$prev) + 1 ))
} | awk '{ printf("%s ", $0) }' | grep -F "$curr"
tagfile-dependabot:
runs-on: ubuntu-latest
if: ${{ startsWith(github.event.pull_request.head.ref, 'dependabot/') }}
permissions:
contents: write
pull-requests: write
steps:
- uses: dependabot/fetch-metadata@v1
id: metadata
with:
skip-commit-verification: true
github-token: "${{ secrets.GITHUB_TOKEN }}"
- uses: actions/checkout@v3
with:
fetch-depth: 0 # For $ git tag
ref: ${{ github.event.pull_request.head.ref }}
- name: Checkout master Tagfile
uses: actions/checkout@v3
with:
ref: master
path: ./master-Tagfile
sparse-checkout: Tagfile
sparse-checkout-cone-mode: false
- name: Ensure Tagfile has changes
run: |
if ! diff -q Tagfile ./master-Tagfile/Tagfile; then
cat ./master-Tagfile/Tagfile | awk -F. '/[0-9]+\./{$NF++;print}' OFS=. >Tagfile
fi
- name: Ensure Tagfile is bumping master Tagfile
run: |
if ! printf '%s pr\n%s master\n' "$(cat Tagfile)" "$(cat ./master-Tagfile/Tagfile)" | sort -u -V -k1 -r | head -n1 | grep master; then
cat ./master-Tagfile/Tagfile | awk -F. '/[0-9]+\./{$NF++;print}' OFS=. >Tagfile
fi
- name: Maybe push new Tagfile
run: |
set -x
git add Tagfile
COMMITHASH=$(git rev-parse --short HEAD)
if git status -bs Tagfile | grep Tagfile; then
git config --global user.name 'dependabot[bot]'
git config --global user.email '49699333+dependabot[bot]@users.noreply.github.com'
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/managing-pull-requests-for-dependency-updates#allowing-dependabot-to-rebase-and-force-push-over-extra-commits
git commit --fixup "$COMMITHASH"
EDITOR=/usr/bin/cat git rebase -i --autosquash "$COMMITHASH"~
git push --force origin "$BRANCH"
fi
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
check-goimports:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
with:
go-version: '>=1.17.0'
- run: go install github.com/incu6us/goimports-reviser/[email protected]
- run: which goimports-reviser
- run: find . -type f -iname '*.go' ! -iname '*.pb.go' -exec goimports-reviser -file-path {} \;
- run: git --no-pager diff --exit-code
check-nillness:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
- run: go run golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@latest ./...
checks:
runs-on: ubuntu-latest
strategy:
matrix:
check:
- goreleaser-dist
- ci-check--lint
- ci-check--mod
- ci-check--test
- ci-check--protolock
# - ci-check--protolock-force
- ci-check--protoc
steps:
- name: Set lowercase image name
run: echo IMAGE=ghcr.io/${SLUG,,} >>$GITHUB_ENV
env:
SLUG: ${{ github.repository }}
- uses: actions/checkout@v3
- uses: docker/[email protected]
- name: Log in to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/[email protected]
with:
files: ./docker-bake.hcl
targets: ${{ matrix.check }}
# TODO: cache-to
# set: |
# *.cache-to=type=registry,ref=${{ env.IMAGE }}:${{ matrix.check }},mode=max
- run: git --no-pager diff --exit-code
# TODO: cache-to
# - if: github.ref == 'refs/heads/master'
# name: If on master push image to GHCR
# run: docker push ${{ env.IMAGE }}:${{ matrix.check }}
- if: matrix.check == 'goreleaser-dist'
name: Test CLI
run: |
tar zxvf ./dist/monkey-Linux-x86_64.tar.gz -C .
./monkey -h | grep monkey
./monkey help | grep monkey
./monkey version
./monkey fmt
[[ $(./monkey version | wc -l) = 1 ]]
./monkey version | grep -F $(cat Tagfile)
./monkey --version | grep -F $(cat Tagfile)