blob: 261e3de0ec7c9e7bc18021ef8c5d99cbdb50b242 [file] [log] [blame]
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------
name: coverage
on:
schedule:
- cron: '45 1 * * *'
workflow_dispatch:
jobs:
test:
if: github.repository == 'apache/camel-k'
runs-on: ubuntu-latest
name: Update Coverage Badge
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: '1.18'
check-latest: true
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Test
run: |
go test -v ./... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
touch badge.out
- name: Go Coverage Badge
uses: ./.github/actions/coverage-badge
with:
filename: coverage.out
target: badge.out
- name: Convert Badge to adoc
run: |
replacement=$(grep -o 'https://[^)]*' badge.out)
target="(?:https:\/\/img\.shields\.io\/badge\/Coverage).*?(?=\.svg)"
perl -i -pe "s|${target}|${replacement}|g" README.adoc
- name: Commit changes
shell: bash
env:
CI_USER: "github-actions[bot]"
CI_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
run: |
git config --local user.email "$CI_EMAIL"
git config --local user.name "$CI_USER"
git add -A && git commit -m 'chore: nightly coverage badge' && echo "refresh=1" >> $GITHUB_ENV || echo "No changes to make update-docs"
- name: Push changes
shell: bash
if: env.changelog == 1 || env.refresh == 1
env:
CI_USER: "github-actions[bot]"
CI_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
CI_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push "https://$CI_USER:$CI_TOKEN@github.com/$GITHUB_REPOSITORY.git" '${{ github.ref_name }}'