Skip to content

Commit

Permalink
ci: experiments with github actions
Browse files Browse the repository at this point in the history
This PR exhibits experimental musings with github actions.

The objectives are:
* [x] try to avoid running a full test suite when only doc is updates
  (i.e. *.md files)
* [x] add some spell & grammar checking on doc (code is checked by a
  linter)
* [x] keep required checks, as they are desirable to properly check
  auto-merged PRs
* [ ] try to throttle macos runners and avoid failures due to the lower
  limit on macos runners

Signed-off-by: Frederic BIDON <[email protected]>
  • Loading branch information
fredbi committed Feb 7, 2024
1 parent cf185d6 commit 9780925
Showing 1 changed file with 90 additions and 3 deletions.
93 changes: 90 additions & 3 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,85 @@ on:
pull_request:

jobs:
changes:
outputs:
notonlydoc: ${{ steps.filter.outputs.notonlydoc }} # <- true if anything else than doc has been changed
doc: ${{ steps.filter.outputs.doc }} # <- true if any doc has been changed
runs-on: ubuntu-latest
permissions:
pull-requests: read

steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
notonlydoc:
- '**/!(*.md)' # <- anything but markdown
doc:
- added|modified: '**.md' # <- any markdown
merge-ok:
if: ${{ always() }}
name: MergeOK
needs: [changes, test_ok, doc_ok]
runs-on: ubuntu-latest
steps:
- run: |
not_doc_only="${{ needs.changes.outputs.notonlydoc }}"
doc="${{ needs.changes.outputs.doc }}"
merge_ok_doc="${{ needs.doc_ok.output.merge_status }}"
merge_ok_test="${{ needs.test_ok.output.merge_status }}"
if [[ "${not_doc_only}" != "true" && "${doc}" != "true" ]] ; then
echo "Change capture error. Should have not doc only, or docs or both."
exit 1
fi
if [[ "${not_doc_only}" == "true" && "${merge_ok_test}" != "true" ]] ; then
echo "Merge KO"
exit 1
fi
if [[ "${doc}" == "true" && "${merge_ok_doc}" != "true" ]] ; then
echo "Merge KO"
exit 1
fi
echo "Merge OK"
test_ok:
needs: [lint, test]
outputs:
merge_status: ${ steps.set_merge_ok.merge_status}
runs-on: ubuntu-latest
steps:
- run: |
echo "::set-output name=merge_status::true"
doc_ok:
needs: [spell-checking]
outputs:
merge_status: ${ steps.set_merge_ok.merge_status}
runs-on: ubuntu-latest
steps:
- run: |
echo "::set-output name=merge_status::true"
lint:
name: Lint
runs-on: ubuntu-latest
needs: [changes]
if: ${{ needs.changes.outputs.notonlydoc == 'true' }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
check-latest: true
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand All @@ -29,6 +98,8 @@ jobs:

test:
name: Unit tests
needs: [changes]
if: ${{ needs.changes.outputs.notonlydoc == 'true' }}
runs-on: ${{ matrix.os }}

strategy:
Expand All @@ -43,10 +114,13 @@ jobs:
go-version: '${{ matrix.go_version }}'
check-latest: true
cache: true

- uses: actions/checkout@v4

- run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic -coverpkg=$(go list)/... ./...
- run: >
go test -v -race
-coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out"
-covermode=atomic
-coverpkg=$(go list)/...
./...
- name: Upload coverage to codecov
uses: codecov/codecov-action@v4
Expand All @@ -56,3 +130,16 @@ jobs:
os: '${{ matrix.os }}'
fail_ci_if_error: false
verbose: true

spell-checking:
name: Doc spell checking
if: ${{ needs.changes.outputs.doc == 'true' }}
needs: [changes]
runs-on: ubuntu-latest

steps:
- uses: check-spelling/check-spelling@main
with:
only: '\.md$'
checkout: 1
#only_check_changed_files: 1

0 comments on commit 9780925

Please sign in to comment.