-
Notifications
You must be signed in to change notification settings - Fork 27
103 lines (86 loc) · 3.23 KB
/
github-workflow.yaml
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
# yamllint disable rule:line-length
---
name: Coverage
# yamllint disable-line rule:truthy
on:
push:
branches:
- master
- dev
jobs:
coverage:
runs-on: ubuntu-22.04
container:
image: kcov/kcov:v42
options: --privileged
steps:
- name: Checkout code
uses: actions/checkout@v3.6.0
- name: Install necessary tools (Git and Curl)
run: |
apt-get update && apt-get install -y curl git jq smartmontools
- name: Install specific version of bats
run: |
curl -L https://github.com/bats-core/bats-core/archive/v1.4.1.tar.gz | tar -xz
cd bats-core-1.4.1
./install.sh /usr/local
rm -rf bats-core-1.4.1
- name: Checkout code with submodules
uses: actions/checkout@v3
with:
submodules: true # Fetch all submodules
fetch-depth: 0 # Fetch full history, required for submodules
submodule-token: ${{ secrets.GITHUB_TOKEN }} # Ensure access to private submodules if needed
- name: Run coverage script with Bash
run: |
chmod +x ./coverage.sh
bash ./coverage.sh
- name: Extract coverage percentage from index.js
id: coverage
shell: bash
run: |
coverage=$(grep -oP '(?<=covered":")[^"]+' ./coverage/test_smartmon.coverage/index.js | head -n 1)
echo "Extracted coverage percentage: $coverage"
echo "::set-output name=coverage::$coverage"
- name: Print Current Working Directory
run: pwd
- name: Configure Git Safe Directory
run: |
git config --global --add safe.directory "$(pwd)"
- name: Update README.md with coverage badge
run: |
current_coverage=$(grep -oP '(?<=Coverage-)\d+\.\d+(?=%25)' README.md)
if [[ "$current_coverage" != "$coverage" ]]; then
sed -i 's|https:\/\/img\.shields\.io\/badge\/Coverage-[0-9]*\(\.[0-9]*\)\?%25-brightgreen|https:\/\/img\.shields\.io\/badge\/Coverage-$coverage%25-brightgreen|g' README.md
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md # Ensure README.md is staged
git commit -m "Update coverage badge"
git push origin ${GITHUB_REF#refs/heads/}
else
echo "Coverage percentage has not changed. Skipping update."
fi
docker-build:
runs-on: ubuntu-22.04
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3.6.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker container
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository_owner }}/smartmon:latest