From a7494eda993f9ca519007ac12e1344a1a1f19cc0 Mon Sep 17 00:00:00 2001 From: SuperQ Date: Mon, 23 Dec 2024 21:49:34 +0100 Subject: [PATCH] Update build * Update Go to 1.23. * Update minimum Go version to 1.21. * Enable golangci-lint action. * Enable dependabot. * Pin GitHub actions to SHA sums for supply chain security. * Fix linting issues. Signed-off-by: SuperQ --- .github/dependabot.yml | 10 ++++++++ .github/workflows/build.yml | 6 ++--- .github/workflows/docker.yml | 8 +++---- .github/workflows/golangci-lint.yml | 36 +++++++++++++++++++++++++++++ .golangci.yml | 11 +++++++++ Dockerfile | 2 +- go.mod | 3 +-- go.sum | 2 -- main.go | 5 +++- mpegts/parser.go | 7 +++--- 10 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..c0b195d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "monthly" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e04c04a..bde94a3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,12 +6,12 @@ jobs: build: runs-on: "ubuntu-22.04" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 with: - go-version: 1.18 + go-version: 1.23 - name: Install dependencies run: ./scripts/install-dependencies.sh diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 91abd63..5c1f715 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,10 +11,10 @@ jobs: runs-on: "ubuntu-latest" steps: - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0 - name: Login to Github Packages - uses: docker/login-action@v1 + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -22,13 +22,13 @@ jobs: - name: Build and push id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0 with: push: true tags: ghcr.io/voc/srtrelay/srtrelay:latest - name: Delete old containers - uses: actions/delete-package-versions@v4 + uses: actions/delete-package-versions@e5bc658cc4c965c472efe991f8beea3981499c55 # v5.0.0 with: package-name: 'srtrelay' package-type: 'container' diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..0b15f9d --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,36 @@ +--- +name: golangci-lint +on: + push: + paths: + - "go.sum" + - "go.mod" + - "**.go" + - ".github/workflows/golangci-lint.yml" + - ".golangci.yml" + pull_request: + +permissions: # added using https://github.com/step-security/secure-repo + contents: read + +jobs: + golangci: + permissions: + contents: read # for actions/checkout to fetch code + pull-requests: read # for golangci/golangci-lint-action to fetch pull requests + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Install Go + uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 + with: + go-version: 1.23.x + - name: Install dependencies + run: ./scripts/install-dependencies.sh + - name: Lint + uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 + with: + args: --verbose + version: v1.62.0 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b6cc42f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,11 @@ +--- +linters: + enable: + - goimports + - misspell + +issues: + exclude-rules: + - path: _test.go + linters: + - errcheck diff --git a/Dockerfile b/Dockerfile index a62ecd6..4599b47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1 -FROM golang:1.18-bullseye AS build +FROM golang:1.23-bullseye AS build RUN apt-get update && \ apt-get upgrade -y && \ diff --git a/go.mod b/go.mod index bc77858..de6ebd2 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,11 @@ module github.com/voc/srtrelay -go 1.18 +go 1.21 require ( github.com/Showmax/go-fqdn v1.0.0 github.com/haivision/srtgo v0.0.0-20230627061225-a70d53fcd618 github.com/pelletier/go-toml/v2 v2.2.2 - google.golang.org/protobuf v1.34.2 gotest.tools/v3 v3.5.1 ) diff --git a/go.sum b/go.sum index 4ffbcb4..7b4ae5c 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,6 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8 golang.org/x/sys v0.0.0-20200926100807-9d91bd62050c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/main.go b/main.go index 4a8c012..8c2a882 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,10 @@ func main() { configFlags := flag.NewFlagSet("config", flag.ContinueOnError) configFlags.SetOutput(io.Discard) configPath := configFlags.String("config", "config.toml", "") - configFlags.Parse(os.Args[1:]) + err := configFlags.Parse(os.Args[1:]) + if err != nil { + log.Fatal(err) + } // parse config conf, err := config.Parse([]string{*configPath, "/etc/srtrelay/config.toml"}) diff --git a/mpegts/parser.go b/mpegts/parser.go index ee4c9a5..652c08a 100644 --- a/mpegts/parser.go +++ b/mpegts/parser.go @@ -28,9 +28,10 @@ const ( // Parser object for finding the synchronization point in a MPEGTS stream // This works as follows: parse packets until all the following have been fulfilled -// 1. Parse PAT to get PID->PMT mappings -// 2. Parse PMTs to Find PID->PES mappings -// 3. Parse PES to find H.264 SPS+PPS or equivalent +// 1. Parse PAT to get PID->PMT mappings +// 2. Parse PMTs to Find PID->PES mappings +// 3. Parse PES to find H.264 SPS+PPS or equivalent +// // Store the original packets or generate new ones to send to a client type Parser struct { init [][]byte // collected packets to initialize a decoder