Skip to content

Commit 633629b

Browse files
authored
ci: switch to Github Actions (#40)
This change replaces CircleCI in favor of GHA, and also drops support for versions of Go (< 1.8) that didn't copy headers when following redirects. I've also added support for testing a minimum Go version in CI, along with associated documentation updates.
2 parents 03fbc55 + 7a48fc0 commit 633629b

File tree

24 files changed

+339
-137
lines changed

24 files changed

+339
-137
lines changed

.circleci/config.yml

Lines changed: 0 additions & 62 deletions
This file was deleted.
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
9+
runs:
10+
using: composite
11+
steps:
12+
- uses: ./.github/actions/get-go-version
13+
id: go-version
14+
- name: Lint
15+
if: inputs.lint == 'true'
16+
shell: bash
17+
run: make lint
18+
19+
- name: Test
20+
shell: bash
21+
id: test
22+
run: make test | tee raw_report.txt
23+
24+
- name: Process test results
25+
if: steps.test.outcome == 'success'
26+
id: process-test
27+
shell: bash
28+
run: go run github.com/jstemmer/[email protected] < raw_report.txt > junit_report.xml
29+
30+
- name: Upload test results
31+
if: steps.process-test.outcome == 'success'
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: Test-result-${{ steps.go-version.outputs.version }}
35+
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.22
2+
penultimate=1.21
3+
min=1.17
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
env:
39+
officialLatestVersion: ${{ needs.check-go-eol.outputs.latest }}
40+
officialPenultimateVersion: ${{ needs.check-go-eol.outputs.penultimate }}
41+
steps:
42+
- uses: actions/checkout@v4
43+
- name: Get current Go versions
44+
id: go-versions
45+
run: cat ./.github/variables/go-versions.env > $GITHUB_OUTPUT
46+
47+
- name: Update go-versions.env and README.md
48+
if: steps.go-versions.outputs.latest != env.officialLatestVersion
49+
id: update-go-versions
50+
run: |
51+
sed -i -e "s#latest=[^ ]*#latest=${{ env.officialLatestVersion }}#g" \
52+
-e "s#penultimate=[^ ]*#penultimate=${{ env.officialPenultimateVersion }}#g" \
53+
./.github/variables/go-versions.env
54+
sed -i "s/Go version ${{ steps.go-versions.outputs.penultimate }}/Go version ${{ env.officialPenultimateVersion }}/g" \
55+
README.md
56+
57+
- name: Create pull request
58+
if: steps.update-go-mod.outcome == 'success'
59+
uses: peter-evans/create-pull-request@v6
60+
with:
61+
token: ${{ secrets.GITHUB_TOKEN }}
62+
add-paths: |
63+
.github/variables/go-versions.env
64+
README.md
65+
branch: "launchdarklyreleasebot/update-to-go${{ env.officialLatestVersion }}-${{ matrix.branch }}"
66+
author: "LaunchDarklyReleaseBot <[email protected]>"
67+
committer: "LaunchDarklyReleaseBot <[email protected]>"
68+
labels: ${{ matrix.branch }}
69+
title: "fix(deps): bump supported Go versions to ${{ env.officialLatestVersion }} and ${{ env.officialPenultimateVersion }}"
70+
commit-message: "Bumps from Go ${{ steps.go-versions.outputs.latest }} -> ${{ env.officialLatestVersion }} and ${{ steps.go-versions.outputs.penultimate }} -> ${{ env.officialPenultimateVersion }}."
71+
body: |
72+
- [ ] 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: [ 'main', 'feat/**' ]
5+
paths-ignore:
6+
- '**.md' # Don't run CI on markdown changes.
7+
pull_request:
8+
branches: [ 'main', '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 ./...

.github/workflows/common_ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Common CI
2+
on:
3+
workflow_call:
4+
inputs:
5+
go-version:
6+
description: "Go version to use for the jobs."
7+
required: true
8+
type: string
9+
10+
jobs:
11+
unit-tests:
12+
runs-on: ubuntu-latest
13+
name: 'Unit Tests'
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Setup Go ${{ inputs.go-version }}
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: ${{ inputs.go-version }}
20+
- uses: ./.github/actions/unit-tests
21+
with:
22+
lint: 'true'
23+
24+
contract-tests:
25+
runs-on: ubuntu-latest
26+
name: 'Contract Tests'
27+
env:
28+
TEST_SERVICE_PORT: 8000
29+
steps:
30+
- uses: actions/checkout@v4
31+
- name: Setup Go ${{ inputs.go-version }}
32+
uses: actions/setup-go@v5
33+
with:
34+
go-version: ${{ inputs.go-version }}
35+
- uses: ./.github/actions/get-go-version
36+
id: go-version
37+
- name: Start test service in background
38+
run: make start-contract-test-service-bg
39+
- uses: launchdarkly/gh-actions/actions/[email protected]
40+
continue-on-error: true
41+
with:
42+
test_service_port: ${{ env.TEST_SERVICE_PORT }}
43+
token: ${{ secrets.GITHUB_TOKEN }}
44+
- name: Upload test service logs
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: Contract-test-service-logs-${{ steps.go-version.outputs.version }}
48+
path: /tmp/sdk-contract-test-service.log

.github/workflows/go-versions.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# The following chunk of yml boils down to pulling two Go version numbers out of a file and
2+
# making them available to the other workflows in a convenient fashion.
3+
#
4+
# It's a reusable workflow instead of an action so that its output can be used in a matrix strategy
5+
# of another job.
6+
#
7+
# The idea is to define the most recent, and penultimate, Go versions that should be used to test Relay.
8+
# Ideally we'd define these in a single place - otherwise we'd need to update many different places in
9+
# each workflow. This single place is .github/variables/go-versions.env.
10+
#
11+
# This reusable workflow grabs them out of the file, then sets them as outputs. As a convenience, it
12+
# also wraps each version in an array, so it can be directly used in a matrix strategy. Single-item matrices
13+
# are nice because you can tell instantly in the Github UI which version is being tested without needing
14+
# to inspect logs.
15+
#
16+
# To use a matrix output, e.g. latest version, do:
17+
# strategy:
18+
# matrix: ${{ fromJSON(this-job.outputs.latest-matrix) }}
19+
#
20+
name: Go Versions
21+
on:
22+
workflow_call:
23+
outputs:
24+
latest:
25+
description: 'The most recent Go version to test'
26+
value: ${{ jobs.go-versions.outputs.latest }}
27+
penultimate:
28+
description: 'The second most recent Go version to test'
29+
value: ${{ jobs.go-versions.outputs.penultimate }}
30+
min:
31+
description: 'The minimum Go version to test'
32+
value: ${{ jobs.go-versions.outputs.min }}
33+
matrix:
34+
description: 'All Go versions to test as a matrix'
35+
value: ${{ jobs.go-versions.outputs.all }}
36+
37+
jobs:
38+
go-versions:
39+
runs-on: ubuntu-latest
40+
outputs:
41+
latest: ${{ steps.set-env.outputs.latest }}
42+
penultimate: ${{ steps.set-env.outputs.penultimate }}
43+
all: ${{ steps.set-matrix.outputs.all }}
44+
steps:
45+
- uses: actions/checkout@v4
46+
- name: Set Go Versions
47+
id: set-env
48+
run: cat ./.github/variables/go-versions.env > $GITHUB_OUTPUT
49+
- name: Set Go Version Matrices
50+
id: set-matrix
51+
run: |
52+
echo "all=[\"${{ steps.set-env.outputs.latest }}\",\"${{ steps.set-env.outputs.penultimate }}\",\"${{ steps.set-env.outputs.min }}\"]" >> $GITHUB_OUTPUT

.github/workflows/stale.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: 'Close stale issues and PRs'
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
# Happen once per day at 1:30 AM
6+
- cron: '30 1 * * *'
7+
8+
jobs:
9+
sdk-close-stale:
10+
uses: launchdarkly/gh-actions/.github/workflows/sdk-stale.yml@main

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin/
22
.vscode/
3+
.idea

0 commit comments

Comments
 (0)