Skip to content

Commit

Permalink
ci: convert to Github Actions (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld authored Aug 19, 2024
1 parent 6e2843e commit c4c898c
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 121 deletions.
119 changes: 0 additions & 119 deletions .circleci/config.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/actions/benchmarks/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Benchmarks
description: "Runs performance benchmarks."

runs:
using: composite
steps:
- uses: ./.github/actions/get-go-version
id: go-version

- name: Run Benchmarks
id: benchmarks
shell: bash
run: make benchmarks | tee benchmarks.txt

- name: Upload Results
if: steps.benchmarks.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: Benchmarks-${{ steps.go-version.outputs.version }}
path: benchmarks.txt
41 changes: 41 additions & 0 deletions .github/actions/coverage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Coverage
description: "Runs code-coverage checker."
inputs:
enforce:
description: 'Whether to enforce coverage thresholds.'
required: false
default: 'false'


runs:
using: composite
steps:
- uses: ./.github/actions/get-go-version
id: go-version

- name: Test with coverage
shell: bash
id: test-coverage
run: |
set +e
make test-coverage
status=$?
echo "coverage_status=$status" >> $GITHUB_OUTPUT
- name: Upload coverage results
uses: actions/upload-artifact@v4
with:
name: Coverage-result-${{ steps.go-version.outputs.version }}
path: build/coverage*

- name: Enforce coverage
shell: bash
run: |
if [ "${{ steps.test-coverage.outputs.coverage_status }}" != "0" ]; then
echo "Code isn't fully covered!"
if [ "${{ inputs.enforce }}" == "true" ]; then
exit 1
fi
else
echo "Code is fully covered!"
fi
15 changes: 15 additions & 0 deletions .github/actions/get-go-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Get Go Version
description: "Gets the currently installed Go version."
outputs:
version:
description: 'The currently installed Go version.'
value: ${{ steps.go-version.outputs.value }}

runs:
using: composite
steps:
- name: Get Go version
id: go-version
shell: bash
run: |
echo "value=$(go version | awk '{print $3}')" >> $GITHUB_OUTPUT
35 changes: 35 additions & 0 deletions .github/actions/unit-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Unit Tests
description: "Runs go-semver's unit tests + linters and optionally gathers coverage."
inputs:
lint:
description: 'Whether to run linters.'
required: false
default: 'false'

runs:
using: composite
steps:
- uses: ./.github/actions/get-go-version
id: go-version
- name: Lint
if: inputs.lint == 'true'
shell: bash
run: make lint

- name: Test
shell: bash
id: test
run: make test | tee raw_report.txt

- name: Process test results
if: steps.test.outcome == 'success'
id: process-test
shell: bash
run: go run github.com/jstemmer/[email protected] < raw_report.txt > junit_report.xml

- name: Upload test results
if: steps.process-test.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: Test-result-${{ steps.go-version.outputs.version }}
path: junit_report.xml
2 changes: 2 additions & 0 deletions .github/variables/go-versions.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
latest=1.22
penultimate=1.21
89 changes: 89 additions & 0 deletions .github/workflows/check-go-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Check Supported Go Versions
on:
schedule:
- cron: "0 17 * * *"
workflow_dispatch:

jobs:
check-go-eol:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.parse.outputs.latest }}
penultimate: ${{ steps.parse.outputs.penultimate }}
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
# Perform a GET request to endoflife.date for the Go language. The response
# contains all Go releases; we're interested in the 0'th and 1'th (latest and penultimate.)
- name: Fetch officially supported Go versions
uses: JamesIves/fetch-api-data-action@396ebea7d13904824f85b892b1616985f847301c
with:
endpoint: https://endoflife.date/api/go.json
configuration: '{ "method": "GET" }'
debug: true
# Parse the response JSON and insert into environment variables for the next step.
- name: Parse officially supported Go versions
id: parse
run: |
echo "latest=${{ fromJSON(env.fetch-api-data)[0].cycle }}" >> $GITHUB_OUTPUT
echo "penultimate=${{ fromJSON(env.fetch-api-data)[1].cycle }}" >> $GITHUB_OUTPUT
create-prs:
permissions:
contents: write
pull-requests: write
needs: check-go-eol
runs-on: ubuntu-latest
strategy:
matrix:
branch: ["v6", "v7"]
fail-fast: false
env:
officialLatestVersion: ${{ needs.check-go-eol.outputs.latest }}
officialPenultimateVersion: ${{ needs.check-go-eol.outputs.penultimate }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}

- name: Get current Go versions
id: go-versions
run: cat ./.github/variables/go-versions.env > $GITHUB_OUTPUT

- name: Update go-versions.env and README.md
if: steps.go-versions.outputs.latest != env.officialLatestVersion
id: update-go-versions
run: |
sed -i -e "s#latest=[^ ]*#latest=${{ env.officialLatestVersion }}#g" \
-e "s#penultimate=[^ ]*#penultimate=${{ env.officialPenultimateVersion }}#g" \
./.github/variables/go-versions.env
sed -i "s/Go version ${{ steps.go-versions.outputs.penultimate }}/Go version ${{ env.officialPenultimateVersion }}/g" \
README.md
- name: Update go.mod and testservice/go.mod
if: steps.update-go-versions.outcome == 'success'
id: update-go-mod
run: |
go mod edit -go=${{ env.officialPenultimateVersion }}
cd testservice
go mod edit -go=${{ env.officialPenultimateVersion }}
- name: Create pull request
if: steps.update-go-mod.outcome == 'success'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: |
.github/variables/go-versions.env
README.md
go.mod
testservice/go.mod
branch: "launchdarklyreleasebot/update-to-go${{ env.officialLatestVersion }}-${{ matrix.branch }}"
author: "LaunchDarklyReleaseBot <[email protected]>"
committer: "LaunchDarklyReleaseBot <[email protected]>"
labels: ${{ matrix.branch }}
title: "fix(deps): bump supported Go versions to ${{ env.officialLatestVersion }} and ${{ env.officialPenultimateVersion }}"
commit-message: "Bumps from Go ${{ steps.go-versions.outputs.latest }} -> ${{ env.officialLatestVersion }} and ${{ steps.go-versions.outputs.penultimate }} -> ${{ env.officialPenultimateVersion }}."
body: |
- [ ] 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`)
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and Test
on:
push:
branches: [ 'master', 'feat/**' ]
paths-ignore:
- '**.md' # Don't run CI on markdown changes.
pull_request:
branches: [ 'master', 'feat/**' ]
paths-ignore:
- '**.md'

jobs:
go-versions:
uses: ./.github/workflows/go-versions.yml

# Runs the common tasks (unit tests, lint, contract tests) for each Go version.
test-linux:
name: ${{ format('Linux, Go {0}', matrix.go-version) }}
needs: go-versions
strategy:
# Let jobs fail independently, in case it's a single version that's broken.
fail-fast: false
matrix:
go-version: ${{ fromJSON(needs.go-versions.outputs.matrix) }}
uses: ./.github/workflows/common_ci.yml
with:
go-version: ${{ matrix.go-version }}

test-windows:
name: ${{ format('Windows, Go {0}', matrix.go-version) }}
runs-on: windows-2022
needs: go-versions
strategy:
fail-fast: false
matrix:
go-version: ${{ fromJSON(needs.go-versions.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Test
run: go test -race ./...
Loading

0 comments on commit c4c898c

Please sign in to comment.