Skip to content

Commit

Permalink
Merge pull request #1 from smlx/actions-draft
Browse files Browse the repository at this point in the history
Add github actions
  • Loading branch information
smlx authored Nov 24, 2023
2 parents d3d563c + 220f6ef commit 1564a71
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 10 deletions.
15 changes: 15 additions & 0 deletions .github/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Configuration = {
/*
* Resolve and load @commitlint/config-conventional from node_modules.
* Referenced packages must be installed
*/
extends: ['@commitlint/config-conventional'],
/*
* Any rules defined here will override rules from @commitlint/config-conventional
*/
rules: {
'body-max-line-length': [1, 'always', 80],
},
};

module.exports = Configuration;
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: docker
directory: /
schedule:
interval: daily
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
14 changes: 14 additions & 0 deletions .github/dependency-review-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This list is the CNCF list, without the Golang license and with the MPL.
# https://github.com/cncf/foundation/blob/main/allowed-third-party-license-policy.md
allow-licenses:
- 'Apache-2.0'
- 'BSD-2-Clause'
- 'BSD-2-Clause-FreeBSD'
- 'BSD-3-Clause'
- 'ISC'
- 'MIT'
- 'MPL-2.0'
- 'PostgreSQL'
- 'Python-2.0'
- 'X11'
- 'Zlib'
70 changes: 70 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: stable
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: build --snapshot --clean
- name: Tar up binaries
# work around limitations in the upload/download artifact actions
# https://github.com/actions/download-artifact#limitations
run: tar -cvf dist.tar dist
- name: Upload binaries tar file
uses: actions/upload-artifact@v3
with:
name: dist.tar
path: dist.tar
buildimage:
if: ${{ !startsWith(github.head_ref, 'dependabot/') }}
strategy:
matrix:
binary:
- sems_mitm_exporter
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download binaries tar file
uses: actions/download-artifact@v3
with:
name: dist.tar
- name: Untar binaries
run: tar -xvf dist.tar
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
# this id is namespaced per matrix run
id: docker_metadata
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/${{ matrix.binary }}
- name: Build and push ${{ matrix.binary }} container image
id: docker_build
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.docker_metadata.outputs.tags }}
labels: ${{ steps.docker_metadata.outputs.labels }}
file: deploy/docker/Dockerfile
context: dist/${{ matrix.binary }}_linux_amd64_v1
build-args:
- BINARY=${{ matrix.binary }}
32 changes: 32 additions & 0 deletions .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "CodeQL"

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language:
- go
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
30 changes: 30 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Coverage
on:
push:
branches:
- main

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure git
run: |
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Set up go
uses: actions/setup-go@v4
with:
go-version: stable
- name: Calculate coverage
run: |
go test -v -covermode=count -coverprofile=coverage.out.raw -coverpkg=./... ./...
grep -v mock_ coverage.out.raw > coverage.out
- name: Convert coverage to lcov
uses: jandelgado/gcov2lcov-action@v1
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
18 changes: 18 additions & 0 deletions .github/workflows/dependabot-automerge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#enable-auto-merge-on-a-pull-request
name: Dependabot auto-merge
on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
15 changes: 15 additions & 0 deletions .github/workflows/dependency-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Dependency Review'
on:
- pull_request
permissions:
contents: read
jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v3
with:
config-file: '.github/dependency-review-config.yml'
31 changes: 31 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint
on: pull_request
jobs:
golangci-lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=180s
commitlint:
permissions:
pull-requests: read
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Lint commit messages
uses: wagoid/commitlint-github-action@v5
with:
configFile: .github/commitlint.config.js
110 changes: 110 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Release
on:
push:
branches:
- main
jobs:
tag:
runs-on: ubuntu-latest
outputs:
new-tag: ${{ steps.bump-tag.outputs.new }}
new-tag-version: ${{ steps.bump-tag.outputs.new_tag_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: stable
- name: Install ccv
run: >
curl -sSL https://github.com/smlx/ccv/releases/download/v0.3.2/ccv_0.3.2_linux_amd64.tar.gz
| sudo tar -xz -C /usr/local/bin ccv
- name: Bump tag if necessary
id: bump-tag
run: |
if [ -z $(git tag -l $(ccv)) ]; then
git tag $(ccv)
git push --tags
echo "new=true" >> $GITHUB_OUTPUT
echo "new_tag_version=$(git tag --points-at HEAD)" >> $GITHUB_OUTPUT
fi
release:
needs: tag
if: needs.tag.outputs.new-tag == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: stable
- name: Set up environment
run: echo "GOVERSION=$(go version)" >> $GITHUB_ENV
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tar up binaries
run: tar -cvf dist.tar dist
- name: Upload binaries tar file
uses: actions/upload-artifact@v3
with:
name: dist.tar
path: dist.tar
releaseimage:
strategy:
matrix:
binary:
- sems_mitm_exporter
needs:
- tag
- release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download binaries tar file
uses: actions/download-artifact@v3
with:
name: dist.tar
- name: Untar binaries
run: tar -xvf dist.tar
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
# this id is namespaced per matrix run
id: docker_metadata
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/${{ matrix.binary }}
tags: |
${{ needs.tag.outputs.new-tag-version }}
latest
- name: Build and push ${{ matrix.binary }} container image
id: docker_build
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.docker_metadata.outputs.tags }}
labels: ${{ steps.docker_metadata.outputs.labels }}
file: deploy/docker/Dockerfile
context: dist/${{ matrix.binary }}_linux_amd64_v1
build-args:
- BINARY=${{ matrix.binary }}
16 changes: 16 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test
on: pull_request
jobs:
go-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: stable
- name: Run Tests
run: go test -v ./...
3 changes: 3 additions & 0 deletions deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.18
ENTRYPOINT ["/${BINARY}"]
COPY ${BINARY} /
6 changes: 5 additions & 1 deletion mitm/mitm.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ func Serve(ctx context.Context, log *slog.Logger) error {
break
}
// accept incoming connections
listener.SetDeadline(time.Now().Add(listenTimeout))
if err = listener.SetDeadline(time.Now().Add(listenTimeout)); err != nil {
log.Error("couldn't set deadline on listener", slog.Any("error", err))
cancel()
break
}
conn, err := listener.Accept()
if err != nil {
// check if timeout reached
Expand Down
Loading

0 comments on commit 1564a71

Please sign in to comment.