Skip to content

Commit f185d6f

Browse files
committed
Merge branch 'develop'
2 parents e91538b + 5464b38 commit f185d6f

File tree

4 files changed

+107
-28
lines changed

4 files changed

+107
-28
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"

.github/workflows/build.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ on:
1616
type: string
1717
required: true
1818

19+
env:
20+
IMAGE_REGISTRY: asia.gcr.io
21+
1922
jobs:
2023
build:
2124
runs-on: self-hosted
@@ -25,7 +28,7 @@ jobs:
2528
- name: prepare
2629
id: prepare
2730
env:
28-
IMAGE_REPOSITORY: asia.gcr.io/kyber-operation/${{ inputs.cluster }}/${{ inputs.service }}
31+
IMAGE_REPOSITORY: ${{ env.IMAGE_REGISTRY }}/kyber-operation/${{ inputs.cluster }}/${{ inputs.service }}
2932
run: |
3033
#!/bin/bash
3134
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
@@ -38,11 +41,6 @@ jobs:
3841
with:
3942
credentials_json: "${{ secrets.GCR_CREDENTIALS }}"
4043
- uses: google-github-actions/setup-gcloud@v1
41-
- name: Cache Docker layers
42-
uses: actions/cache@v3
43-
with:
44-
path: /tmp/.buildx-cache
45-
key: ${{ runner.os }}-${{ inputs.service }}-buildx
4644
- uses: docker/build-push-action@v5
4745
with:
4846
context: .
@@ -61,9 +59,5 @@ jobs:
6159
${{ steps.prepare.outputs.image_url }}
6260
secrets: |
6361
"gh_pat=${{ secrets.GH_PAT }}"
64-
cache-from: type=local,src=/tmp/.buildx-cache
65-
cache-to: type=local,dest=/tmp/.buildx-cache-new
66-
- name: Move Docker cache
67-
run: |
68-
rm -rf /tmp/.buildx-cache
69-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max

.github/workflows/ci.yaml

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ name: CI
55
# concurrency:
66
# group: ci-workflow-${{ github.ref }}-${{ github.event_name }}
77
# cancel-in-progress: true
8+
# Sample permissions config:
9+
# permissions:
10+
# issues: write
11+
# pull-requests: write
812

913
on:
1014
workflow_call:
@@ -19,6 +23,7 @@ jobs:
1923
- uses: actions/setup-go@v4
2024
with:
2125
go-version-file: 'go.mod'
26+
cache: false
2227

2328
- uses: golangci/golangci-lint-action@v3
2429
with:
@@ -27,6 +32,8 @@ jobs:
2732

2833
test:
2934
runs-on: self-hosted
35+
outputs:
36+
cov: ${{ steps.cov.outputs.cov }}
3037
steps:
3138
- name: Add git config for Go private module
3239
run: git config --global url."https://${{ secrets.GH_PAT }}:x-oauth-basic@github.com/".insteadOf https://github.com/
@@ -36,7 +43,84 @@ jobs:
3643
go-version-file: 'go.mod'
3744

3845
- name: Run tests
39-
run: go test -race -coverprofile cover.out -vet=off ./...
40-
- name: Print coverage
4146
run: |
42-
go tool cover -func cover.out | grep total | awk '{notice="Statement Coverage: " substr($3, 1, length($3))} END {print notice}'
47+
go test -race -cover -vet=off ./... >cover.out || EC=$?;
48+
{ echo '```'; cat cover.out; } | tee -a $GITHUB_STEP_SUMMARY; (exit $EC)
49+
- id: cov
50+
name: Get coverage
51+
run: |
52+
{
53+
echo 'cov<<EOF'
54+
<cover.out grep -v 'no test files' |
55+
awk '{printf "%s b %.2f\n", $2, $5}'
56+
echo 'EOF'
57+
} >> $GITHUB_OUTPUT
58+
59+
test_base:
60+
runs-on: self-hosted
61+
if: github.event_name == 'pull_request'
62+
outputs:
63+
cov: ${{ steps.cov.outputs.cov }}
64+
steps:
65+
- name: Add git config for Go private module
66+
run: git config --global url."https://${{ secrets.GH_PAT }}:x-oauth-basic@github.com/".insteadOf https://github.com/
67+
- uses: actions/checkout@v4
68+
with:
69+
ref: ${{ github.event.pull_request.base.ref }}
70+
- uses: actions/setup-go@v4
71+
with:
72+
go-version-file: 'go.mod'
73+
74+
- id: cov
75+
name: Get coverage
76+
run: |
77+
echo '```' >> $GITHUB_STEP_SUMMARY
78+
{
79+
echo 'cov<<EOF'
80+
go test -covermode=set -vet=off ./... |
81+
tee -a $GITHUB_STEP_SUMMARY |
82+
grep -v 'no test files' |
83+
awk '{printf "%s a %.2f\n", $2, $5}'
84+
echo 'EOF'
85+
} >> $GITHUB_OUTPUT
86+
87+
test_coverage:
88+
runs-on: self-hosted
89+
needs: [test, test_base]
90+
if: github.event_name == 'pull_request' && !cancelled() && needs.test.result == 'success'
91+
steps:
92+
- id: cov
93+
name: Generate coverage report
94+
run: |
95+
{
96+
echo 'report<<EOF'
97+
<<<"${{ needs.test_base.outputs.cov }}"$'\n'"${{ needs.test.outputs.cov }}" sort |
98+
awk 'function diff(a, b) {
99+
if (!a && !b) { return }
100+
printf("| %s | %.2f%% | %.2f%% | %s |\n", pkg, a, b, (a && b < a) ? ":x:" : ":heavy_check_mark:")
101+
}
102+
103+
BEGIN { print("Test coverage changes:\n" \
104+
"| Package | Before | After | Diff |\n" \
105+
"| ------- | -----: | ----: | ---- |")
106+
}
107+
108+
$1 != pkg {
109+
diff(a, b)
110+
a = b = ""
111+
pkg = $1
112+
}
113+
$2 == "a" { a = $3 }
114+
$2 == "b" { b = $3 }
115+
116+
END {
117+
diff(a, b)
118+
}' | tee -a $GITHUB_STEP_SUMMARY
119+
echo 'EOF'
120+
} >> $GITHUB_OUTPUT
121+
- name: Comment PR
122+
uses: thollander/actions-comment-pull-request@v2
123+
with:
124+
pr_number: ${{ github.event.pull_request.number }}
125+
comment_tag: cov
126+
message: ${{ steps.cov.outputs.report }}

.github/workflows/release.yaml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ on:
2121
type: string
2222
required: true
2323

24+
env:
25+
IMAGE_REGISTRY: asia.gcr.io
26+
2427
jobs:
2528
release:
2629
runs-on: self-hosted
@@ -29,7 +32,7 @@ jobs:
2932
- name: prepare
3033
id: prepare
3134
env:
32-
IMAGE_REPOSITORY: asia.gcr.io/kyber-operation/${{ inputs.cluster }}/${{ inputs.service }}
35+
IMAGE_REPOSITORY: ${{ env.IMAGE_REGISTRY }}/kyber-operation/${{ inputs.cluster }}/${{ inputs.service }}
3336
INPUT_TAG: ${{ github.event.inputs.version }}
3437
run: |
3538
#!/bin/bash
@@ -40,13 +43,8 @@ jobs:
4043
- uses: docker/setup-buildx-action@v3
4144
- uses: google-github-actions/auth@v1
4245
with:
43-
credentials_json: '${{ secrets.GCR_CREDENTIALS }}'
46+
credentials_json: "${{ secrets.GCR_CREDENTIALS }}"
4447
- uses: google-github-actions/setup-gcloud@v1
45-
- name: Cache Docker layers
46-
uses: actions/cache@v3
47-
with:
48-
path: /tmp/.buildx-cache
49-
key: ${{ runner.os }}-${{ inputs.service }}-buildx
5048
- uses: docker/build-push-action@v5
5149
with:
5250
context: .
@@ -66,12 +64,8 @@ jobs:
6664
${{ steps.prepare.outputs.image_repository }}:${{ steps.prepare.outputs.version_tag }}
6765
secrets: |
6866
"gh_pat=${{ secrets.GH_PAT }}"
69-
cache-from: type=local,src=/tmp/.buildx-cache
70-
cache-to: type=local,dest=/tmp/.buildx-cache-new
71-
- name: Move Docker cache
72-
run: |
73-
rm -rf /tmp/.buildx-cache
74-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
67+
cache-from: type=gha
68+
cache-to: type=gha,mode=max
7569
- name: Create tag
7670
env:
7771
VERSION_TAG: ${{ steps.prepare.outputs.version_tag }}

0 commit comments

Comments
 (0)