Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/pdf-archiver
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr committed Oct 12, 2024
2 parents 504c15e + 8c35a6b commit 1ef321e
Show file tree
Hide file tree
Showing 32 changed files with 423 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dev-data*
docs
!docs/swagger
Dockerfile
*.md
.githooks
.github
.goreleaser.yaml
/.*
4 changes: 2 additions & 2 deletions .github/workflows/_buildx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Build Docker
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0
- uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # 4.1.7
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # 4.1.8
with:
name: dist
path: ./dist
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/_e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "E2E Tests"

on: workflow_call

jobs:
e2e-tests:
runs-on: ubuntu-latest

name: Tests
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: ./go.mod

- run: make e2e
4 changes: 2 additions & 2 deletions .github/workflows/_golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: golangci-lint
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # 6.0.1
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # 6.1.1
with:
version: latest

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/_gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "flags=--snapshot" >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@5742e2a039330cbb23ebf35f046f814d4c6ff811 # 5.1.0
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # 6.0.0
with:
distribution: goreleaser
version: latest
args: release --clean ${{ env.flags }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # 4.3.3
- uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # 4.4.0
with:
name: dist
path: ./dist/*
4 changes: 2 additions & 2 deletions .github/workflows/_styles-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
styles-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Setup Bun
uses: oven-sh/setup-bun@8f24390df009a496891208e5e36b8a1de1f45135 # v1
uses: oven-sh/setup-bun@4bc047ad259df6fc24a6c9b0f9a0cb08cf17fbe5 # v1
with:
bun-version: "1.0.1"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/_swagger-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
swagger-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'

Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ jobs:

name: Go unit tests (ubuntu-latest)
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Setup go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: ./go.mod

- name: Set up gotestfmt
uses: gotesttools/gotestfmt-action@8b4478c7019be847373babde9300210e7de34bfb # v2.2.0

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # 4.0.2
- uses: actions/cache@2cdf405574d6ef1f33a1d12acccd3ae82f47b3f2 # 4.1.0
with:
path: |
~/.cache/go-build
Expand All @@ -65,7 +65,7 @@ jobs:
- run: go build -tags osusergo,netgo -ldflags="-s -w -X main.version=$(git describe --tags) -X main.date=$(date --iso-8601=seconds)"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # 4.4.1
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # 4.6.0
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Expand All @@ -76,14 +76,14 @@ jobs:
runs-on: ${{ matrix.os }}
name: Go unit tests (${{ matrix.os }})
steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Setup go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: ./go.mod

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # 4.0.2
- uses: actions/cache@2cdf405574d6ef1f33a1d12acccd3ae82f47b3f2 # 4.1.0
with:
path: |
~/.cache/go-build
Expand Down Expand Up @@ -112,10 +112,10 @@ jobs:
version: '7.5'

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0

- name: Test on ${{ matrix.os.name }}
uses: cross-platform-actions/action@b2e15da1e667187766fff4945d20b98ac7055576 # v0.24.0
uses: cross-platform-actions/action@cdc9ee69ef84a5f2e59c9058335d9c57bcb4ac86 # v0.25.0
with:
environment_variables: GO_VERSION
operating_system: ${{ matrix.os.name }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ jobs:
uses: ./.github/workflows/_swagger-check.yml
call-styles-check:
uses: ./.github/workflows/_styles-check.yml
call-gorelease:
call-e2e:
needs: [call-lint, call-test, call-swagger-check, call-styles-check]
uses: ./.github/workflows/_e2e.yml
call-gorelease:
needs: [call-e2e]
uses: ./.github/workflows/_gorelease.yml
call-buildx:
needs: call-gorelease
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ jobs:
uses: ./.github/workflows/_test.yml
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN}}
call-e2e:
uses: ./.github/workflows/_e2e.yml
call-gorelease:
needs: [call-lint, call-test]
needs: [call-lint, call-test, call-e2e]
uses: ./.github/workflows/_gorelease.yml
call-buildx:
needs: call-gorelease
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version_bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0
ref: ${{ inputs.ref }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ dist/
# frontend
node_modules

# golang
go.work*

# workaround for buildx using podman
type=docker
7 changes: 6 additions & 1 deletion Dockerfile.compose
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
FROM docker.io/golang:1.21-alpine3.19
# This Dockerfile is intented for Development purposes only to use
# with the provided docker-compose.yaml file.
# Please do not run this Dockerfile in any environment that is not
# a local development scenario as this is not throroughly updated nor
# tested.
FROM docker.io/golang:1.22-alpine

WORKDIR /src/shiori

Expand Down
14 changes: 14 additions & 0 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG ALPINE_VERSION
ARG GOLANG_VERSION

FROM docker.io/golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION}

WORKDIR /src/shiori

COPY . /src/shiori

RUN apk --update add git && \
go run main.go version # Using this to force go dep download by running the main command.

ENTRYPOINT ["go", "run", "main.go"]
CMD ["server"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ golangci-lint:
unittest:
GIN_MODE=$(GIN_MODE) GO_TEST_FLAGS="$(GO_TEST_FLAGS)" GOTESTFMT_FLAGS="$(GOTESTFMT_FLAGS)" $(BASH) -xe ./scripts/test.sh

## Run end to end tests
.PHONY: e2e
e2e:
$(BASH) -xe ./scripts/e2e.sh

## Build styles
.PHONY: styles
styles:
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Docker compose for development purposes only
# Docker compose for development purposes only.
# Edit it to fit your current development needs.
version: "3"
services:
shiori:
Expand Down
87 changes: 87 additions & 0 deletions e2e/e2eutil/containers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package e2eutil

import (
"context"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)

const (
shioriPort = "8080/tcp"
shioriExpectedStartupMessage = "started http server"
shioriExpectedStartupSeconds = 5
)

var testContainersProviderType testcontainers.ProviderType = testcontainers.ProviderDocker

func init() {
// If TESTCONTAINERS_PROVIDER is set to podman, use podman
// NOTE: This is EXPERIMENTAL since there are some issues running the e2e tests using podman,
// testcontainers implies that it supports podman but I couldn't make it run in my tests.
// YMMV.
// More info: https://golang.testcontainers.org/system_requirements/using_podman/
if os.Getenv("TESTCONTAINERS_PROVIDER") == "podman" {
testContainersProviderType = testcontainers.ProviderPodman
}
}

func newBuildArg(value string) *string {
return &value
}

type ShioriContainer struct {
t *testing.T

Container testcontainers.Container
}

func (sc *ShioriContainer) GetPort() string {
mappedPort, err := sc.Container.MappedPort(context.Background(), shioriPort)
require.NoError(sc.t, err)
return mappedPort.Port()
}

// NewShioriContainer creates a new ShioriContainer which is a wrapper around a testcontainers.Container
// with some helpers for using while running Shiori E2E tests.
func NewShioriContainer(t *testing.T, tag string) ShioriContainer {
containerDefinition := testcontainers.GenericContainerRequest{
ProviderType: testContainersProviderType,
ContainerRequest: testcontainers.ContainerRequest{
Cmd: []string{"server", "--log-level", "debug"},
ExposedPorts: []string{shioriPort},
WaitingFor: wait.ForLog(shioriExpectedStartupMessage).WithStartupTimeout(shioriExpectedStartupSeconds * time.Second),
},
Started: true,
}

if tag != "" {
containerDefinition.ContainerRequest.FromDockerfile = testcontainers.FromDockerfile{}
containerDefinition.Image = "gchr.io/go-shiori/shiori:" + tag
} else {
containerDefinition.FromDockerfile = testcontainers.FromDockerfile{
Context: "../..",
Dockerfile: "Dockerfile.e2e",
KeepImage: true,
BuildArgs: map[string]*string{
"ALPINE_VERSION": newBuildArg(os.Getenv("CONTAINER_ALPINE_VERSION")),
"GOLANG_VERSION": newBuildArg(os.Getenv("GOLANG_VERSION")),
},
}
}

container, err := testcontainers.GenericContainer(context.Background(), containerDefinition)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, container.Terminate(context.Background()))
})

return ShioriContainer{
t: t,
Container: container,
}
}
19 changes: 19 additions & 0 deletions e2e/server/basic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package e2e

import (
"net/http"
"testing"

"github.com/go-shiori/shiori/e2e/e2eutil"
"github.com/stretchr/testify/require"
)

func TestServerBasic(t *testing.T) {
container := e2eutil.NewShioriContainer(t, "")

t.Run("liveness endpoint", func(t *testing.T) {
req, err := http.Get("http://localhost:" + container.GetPort() + "/system/liveness")
require.NoError(t, err)
require.Equal(t, http.StatusOK, req.StatusCode)
})
}
Loading

0 comments on commit 1ef321e

Please sign in to comment.