Skip to content

Commit e12fc41

Browse files
authored
ci: convert to Github Actions (#31)
Converts the repo to Github Actions. I've added CI jobs for: - Minimum Go version - Penultimate supported Go version - Latest supported Go version
1 parent 470be19 commit e12fc41

File tree

16 files changed

+386
-138
lines changed

16 files changed

+386
-138
lines changed

.circleci/config.yml

Lines changed: 0 additions & 131 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Benchmarks
2+
description: "Runs the performance benchmarks."
3+
inputs:
4+
make-target:
5+
description: "The make target to run."
6+
required: true
7+
default: "benchmarks"
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- uses: ./.github/actions/get-go-version
13+
id: go-version
14+
15+
- name: Run Benchmarks
16+
id: benchmarks
17+
shell: bash
18+
run: make ${{ inputs.make-target }} | tee ${{ inputs.make-target}}.txt
19+
20+
- name: Upload Results
21+
if: steps.benchmarks.outcome == 'success'
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: ${{ inputs.make-target }}-${{ steps.go-version.outputs.version }}
25+
path: ${{ inputs.make-target}}.txt
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Coverage
2+
description: "Runs code-coverage checker."
3+
inputs:
4+
enforce:
5+
description: 'Whether to enforce coverage thresholds.'
6+
required: false
7+
default: 'false'
8+
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- uses: ./.github/actions/get-go-version
14+
id: go-version
15+
16+
- name: Test with coverage
17+
shell: bash
18+
id: test-coverage
19+
run: |
20+
set +e
21+
make test-coverage
22+
status=$?
23+
echo "coverage_status=$status" >> $GITHUB_OUTPUT
24+
- name: Upload coverage results
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: Coverage-result-${{ steps.go-version.outputs.version }}
28+
path: build/coverage*
29+
30+
- name: Enforce coverage
31+
shell: bash
32+
run: |
33+
if [ "${{ steps.test-coverage.outputs.coverage_status }}" != "0" ]; then
34+
echo "Code isn't fully covered!"
35+
if [ "${{ inputs.enforce }}" == "true" ]; then
36+
exit 1
37+
fi
38+
else
39+
echo "Code is fully covered!"
40+
fi
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Get Go Version
2+
description: "Gets the currently installed Go version."
3+
outputs:
4+
version:
5+
description: 'The currently installed Go version.'
6+
value: ${{ steps.go-version.outputs.value }}
7+
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Get Go version
12+
id: go-version
13+
shell: bash
14+
run: |
15+
echo "value=$(go version | awk '{print $3}')" >> $GITHUB_OUTPUT
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Unit Tests
2+
description: "Runs unit tests + linters and optionally gathers coverage."
3+
inputs:
4+
lint:
5+
description: 'Whether to run linters.'
6+
required: false
7+
default: 'false'
8+
make-target:
9+
description: 'The make target to run.'
10+
required: false
11+
default: 'test'
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- uses: ./.github/actions/get-go-version
17+
id: go-version
18+
- name: Lint
19+
if: inputs.lint == 'true'
20+
shell: bash
21+
run: make lint
22+
23+
- name: Test
24+
shell: bash
25+
id: test
26+
run: make ${{ inputs.make-target }} | tee raw_report.txt
27+
28+
- name: Process test results
29+
if: steps.test.outcome == 'success'
30+
id: process-test
31+
shell: bash
32+
run: go run github.com/jstemmer/go-junit-report@v0.9.1 < raw_report.txt > junit_report.xml
33+
34+
- name: Upload test results
35+
if: steps.process-test.outcome == 'success'
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: Test-result-${{ inputs.make-target }}${{ steps.go-version.outputs.version }}
39+
path: junit_report.xml

.github/variables/go-versions.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
latest=1.23
2+
penultimate=1.22
3+
min=1.18
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Check Supported Go Versions
2+
on:
3+
schedule:
4+
- cron: "0 17 * * *"
5+
workflow_dispatch:
6+
7+
jobs:
8+
check-go-eol:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
latest: ${{ steps.parse.outputs.latest }}
12+
penultimate: ${{ steps.parse.outputs.penultimate }}
13+
timeout-minutes: 2
14+
steps:
15+
- uses: actions/checkout@v4
16+
# Perform a GET request to endoflife.date for the Go language. The response
17+
# contains all Go releases; we're interested in the 0'th and 1'th (latest and penultimate.)
18+
- name: Fetch officially supported Go versions
19+
uses: JamesIves/fetch-api-data-action@396ebea7d13904824f85b892b1616985f847301c
20+
with:
21+
endpoint: https://endoflife.date/api/go.json
22+
configuration: '{ "method": "GET" }'
23+
debug: true
24+
# Parse the response JSON and insert into environment variables for the next step.
25+
- name: Parse officially supported Go versions
26+
id: parse
27+
run: |
28+
echo "latest=${{ fromJSON(env.fetch-api-data)[0].cycle }}" >> $GITHUB_OUTPUT
29+
echo "penultimate=${{ fromJSON(env.fetch-api-data)[1].cycle }}" >> $GITHUB_OUTPUT
30+
31+
32+
create-prs:
33+
permissions:
34+
contents: write
35+
pull-requests: write
36+
needs: check-go-eol
37+
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
branch: ["v3"]
41+
fail-fast: false
42+
env:
43+
officialLatestVersion: ${{ needs.check-go-eol.outputs.latest }}
44+
officialPenultimateVersion: ${{ needs.check-go-eol.outputs.penultimate }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
ref: ${{ matrix.branch }}
49+
50+
- name: Get current Go versions
51+
id: go-versions
52+
run: cat ./.github/variables/go-versions.env > $GITHUB_OUTPUT
53+
54+
- name: Update go-versions.env and README.md
55+
if: steps.go-versions.outputs.latest != env.officialLatestVersion
56+
id: update-go-versions
57+
run: |
58+
sed -i -e "s#latest=[^ ]*#latest=${{ env.officialLatestVersion }}#g" \
59+
-e "s#penultimate=[^ ]*#penultimate=${{ env.officialPenultimateVersion }}#g" \
60+
./.github/variables/go-versions.env
61+
62+
- name: Create pull request
63+
if: steps.update-go-versions.outcome == 'success'
64+
uses: peter-evans/create-pull-request@v6
65+
with:
66+
token: ${{ secrets.GITHUB_TOKEN }}
67+
add-paths: |
68+
.github/variables/go-versions.env
69+
branch: "launchdarklyreleasebot/update-to-go${{ env.officialLatestVersion }}-${{ matrix.branch }}"
70+
author: "LaunchDarklyReleaseBot <LaunchDarklyReleaseBot@launchdarkly.com>"
71+
committer: "LaunchDarklyReleaseBot <LaunchDarklyReleaseBot@launchdarkly.com>"
72+
labels: ${{ matrix.branch }}
73+
title: "ci: bump tested Go versions to ${{ env.officialLatestVersion }} and ${{ env.officialPenultimateVersion }}"
74+
commit-message: "Bumps from Go ${{ steps.go-versions.outputs.latest }} -> ${{ env.officialLatestVersion }} and ${{ steps.go-versions.outputs.penultimate }} -> ${{ env.officialPenultimateVersion }}."
75+
body: |
76+
- [ ] I have triggered CI on this PR (either close & reopen this PR in Github UI, or `git commit -m "run ci" --allow-empty && git push`)

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build and Test
2+
on:
3+
push:
4+
branches: [ 'v3', 'feat/**' ]
5+
paths-ignore:
6+
- '**.md' # Don't run CI on markdown changes.
7+
pull_request:
8+
branches: [ 'v3', 'feat/**' ]
9+
paths-ignore:
10+
- '**.md'
11+
12+
jobs:
13+
go-versions:
14+
uses: ./.github/workflows/go-versions.yml
15+
16+
# Runs the common tasks (unit tests, lint, contract tests) for each Go version.
17+
test-linux:
18+
name: ${{ format('Linux, Go {0}', matrix.go-version) }}
19+
needs: go-versions
20+
strategy:
21+
# Let jobs fail independently, in case it's a single version that's broken.
22+
fail-fast: false
23+
matrix:
24+
go-version: ${{ fromJSON(needs.go-versions.outputs.matrix) }}
25+
uses: ./.github/workflows/common_ci.yml
26+
with:
27+
go-version: ${{ matrix.go-version }}
28+
29+
test-windows:
30+
name: ${{ format('Windows, Go {0}', matrix.go-version) }}
31+
runs-on: windows-2022
32+
needs: go-versions
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
go-version: ${{ fromJSON(needs.go-versions.outputs.matrix) }}
37+
steps:
38+
- uses: actions/checkout@v4
39+
- name: Setup Go ${{ matrix.go-version }}
40+
uses: actions/setup-go@v5
41+
with:
42+
go-version: ${{ matrix.go-version }}
43+
- name: Test
44+
run: go test -race ./...

0 commit comments

Comments
 (0)