Skip to content

Commit

Permalink
copy grol's workflow (#16)
Browse files Browse the repository at this point in the history
* copy grol's workflow

* linter...

* add makefile for local lint
  • Loading branch information
ldemailly authored Jul 20, 2024
1 parent 0b42f2c commit 6e11695
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 165 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/" # Location of package manifests
schedule:
interval: "daily"
groups:
"fortio":
patterns:
- "fortio.org/*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
40 changes: 40 additions & 0 deletions .github/workflows/gochecks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: go-checks

on:
workflow_call:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
- name: Setup Go environment
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # pin@v5
with:
go-version: '1.22'
check-latest: true
- name: Run Vulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: Download linter config
run: curl -fsS -o .golangci.yml https://raw.githubusercontent.com/fortio/workflows/main/golangci.yml
- name: Run golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # pin@v6
- name: Run tests
run: |
go version
go run . buildinfo || true # to also confirm go toolchain version used
if make -n test &>/dev/null; then
echo "Running tests with make test"
make test
else
echo "No Makefile test target, running tests with race detection as default behavior"
go test -race ./...
fi
43 changes: 43 additions & 0 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release

on:
push:
tags:
# so a vX.Y.Z-test1 doesn't trigger build
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-pre*'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v3
with:
fetch-depth: 0
- uses: docker/setup-qemu-action@5927c834f5b4fdf503fca6f4c7eccda82949e1ee # pin@v1
- uses: docker/setup-buildx-action@4fd812986e6c8c2a69e18311145f9371337f27d4 # pin@v1
- name: Set up Go
uses: actions/setup-go@v5 # pin@v3
with:
go-version: '1.22'
check-latest: true
- name: Log in to Docker
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # pin@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_PAT }}
- name: "GoReleaser Action"
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # [email protected]
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
TAP_DESCRIPTION: "Go Repl Open Language: simple, small but powerful interpreted language in Go"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ go.work.sum

grol-discord-bot
.DS_Store
.golangci.yml
161 changes: 0 additions & 161 deletions .golangci.yml

This file was deleted.

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all: test lint

test:
go test -race ./...

lint: .golangci.yml
CGO_ENABLED=0 golangci-lint run

.golangci.yml: Makefile
curl -fsS -o .golangci.yml https://raw.githubusercontent.com/fortio/workflows/main/golangci.yml

.PHONY: all lint test
11 changes: 7 additions & 4 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (

var BotToken string

// State for edit to replies.
var msgSet *fixedmap.FixedMap[string, string]

const Unknown = "unknown"

func Run(maxHistoryLength int) {
msgSet = fixedmap.NewFixedMap[string, string](maxHistoryLength)
// create a session
Expand Down Expand Up @@ -167,15 +170,15 @@ func handleMessage(session *discordgo.Session, message *discordgo.MessageCreate,
var channelName string
if err != nil {
log.S(log.Error, "unable to get channel info", log.Any("err", err))
channelName = "unknown"
channelName = Unknown
} else {
channelName = channel.Name
}
server, err := session.State.Guild(message.GuildID)
var serverName string
if err != nil {
log.S(log.Error, "unable to get server info", log.Any("err", err))
serverName = "unknown"
serverName = Unknown
} else {
serverName = server.Name
}
Expand Down Expand Up @@ -272,14 +275,14 @@ func interactionCreate(session *discordgo.Session, interaction *discordgo.Intera
channel, err := session.State.Channel(interaction.ChannelID)
if err != nil {
log.S(log.Error, "unable to get channel info", log.Any("err", err))
channelName = "unknown"
channelName = Unknown
} else {
channelName = channel.Name
}
svr, err := session.State.Guild(interaction.GuildID)
if err != nil {
log.S(log.Error, "unable to get server info", log.Any("err", err))
serverName = "unknown"
serverName = Unknown
} else {
serverName = svr.Name
}
Expand Down

0 comments on commit 6e11695

Please sign in to comment.