2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 19:38:57 +00:00
restic/.github/workflows/tests.yml

317 lines
11 KiB
YAML
Raw Normal View History

2019-11-18 20:16:47 +00:00
name: test
on:
# run tests on push to master, but not when other branches are pushed to
push:
branches:
- master
# run tests for all pull requests
pull_request:
env:
2023-03-12 10:35:48 +00:00
latest_go: "1.20.x"
2022-03-20 10:30:01 +00:00
GO111MODULE: on
2019-11-18 20:16:47 +00:00
jobs:
test:
strategy:
matrix:
# list of jobs to run:
include:
- job_name: Windows
2023-03-12 10:35:48 +00:00
go: 1.20.x
2019-11-18 20:16:47 +00:00
os: windows-latest
- job_name: macOS
2023-03-12 10:35:48 +00:00
go: 1.20.x
2019-11-18 20:16:47 +00:00
os: macOS-latest
2020-11-13 20:58:16 +00:00
test_fuse: false
2019-11-18 20:16:47 +00:00
- job_name: Linux
2023-03-12 10:35:48 +00:00
go: 1.20.x
2019-11-18 20:16:47 +00:00
os: ubuntu-latest
test_cloud_backends: true
test_fuse: true
check_changelog: true
2022-11-11 20:58:57 +00:00
- job_name: Linux (race)
2023-03-12 10:35:48 +00:00
go: 1.20.x
2022-11-11 20:58:57 +00:00
os: ubuntu-latest
test_fuse: true
test_opts: "-race"
2023-03-12 10:35:48 +00:00
- job_name: Linux
go: 1.19.x
os: ubuntu-latest
test_fuse: true
2022-08-04 20:07:16 +00:00
- job_name: Linux
go: 1.18.x
os: ubuntu-latest
test_fuse: true
2019-11-18 20:16:47 +00:00
name: ${{ matrix.job_name }} Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
env:
GOPROXY: https://proxy.golang.org
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v4
2019-11-18 20:16:47 +00:00
with:
go-version: ${{ matrix.go }}
- name: Get programs (Linux/macOS)
run: |
echo "build Go tools"
go install github.com/restic/rest-server/cmd/rest-server@latest
2019-11-18 20:16:47 +00:00
echo "install minio server"
mkdir $HOME/bin
if [ "$RUNNER_OS" == "macOS" ]; then
wget --no-verbose -O $HOME/bin/minio https://dl.minio.io/server/minio/release/darwin-amd64/minio
else
wget --no-verbose -O $HOME/bin/minio https://dl.minio.io/server/minio/release/linux-amd64/minio
fi
chmod 755 $HOME/bin/minio
echo "install rclone"
if [ "$RUNNER_OS" == "macOS" ]; then
wget --no-verbose -O rclone.zip https://downloads.rclone.org/rclone-current-osx-amd64.zip
else
wget --no-verbose -O rclone.zip https://downloads.rclone.org/rclone-current-linux-amd64.zip
fi
unzip rclone.zip
cp rclone*/rclone $HOME/bin
chmod 755 $HOME/bin/rclone
rm -rf rclone*
2022-09-24 19:59:36 +00:00
# add $HOME/bin to path ($GOBIN was already added to the path by setup-go@v3)
2019-11-18 20:16:47 +00:00
echo $HOME/bin >> $GITHUB_PATH
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest'
- name: Get programs (Windows)
shell: powershell
run: |
$ProgressPreference = 'SilentlyContinue'
echo "build Go tools"
go install github.com/restic/rest-server/...
2019-11-18 20:16:47 +00:00
echo "install minio server"
mkdir $Env:USERPROFILE/bin
Invoke-WebRequest https://dl.minio.io/server/minio/release/windows-amd64/minio.exe -OutFile $Env:USERPROFILE/bin/minio.exe
echo "install rclone"
Invoke-WebRequest https://downloads.rclone.org/rclone-current-windows-amd64.zip -OutFile rclone.zip
unzip rclone.zip
copy rclone*/rclone.exe $Env:USERPROFILE/bin
2022-09-24 19:59:36 +00:00
# add $USERPROFILE/bin to path ($GOBIN was already added to the path by setup-go@v3)
2019-11-18 20:16:47 +00:00
echo $Env:USERPROFILE\bin >> $Env:GITHUB_PATH
echo "install tar"
cd $env:USERPROFILE
mkdir tar
cd tar
# install exactly these versions of tar and the libraries, other combinations might not work!
2020-11-13 20:56:14 +00:00
Invoke-WebRequest https://github.com/restic/test-assets/raw/master/tar-1.13-1-bin.zip -OutFile tar.zip
2019-11-18 20:16:47 +00:00
unzip tar.zip
2020-11-13 20:56:14 +00:00
Invoke-WebRequest https://github.com/restic/test-assets/raw/master/libintl-0.11.5-2-bin.zip -OutFile libintl.zip
2019-11-18 20:16:47 +00:00
unzip libintl.zip
2020-11-13 20:56:14 +00:00
Invoke-WebRequest https://github.com/restic/test-assets/raw/master/libiconv-1.8-1-bin.zip -OutFile libiconv.zip
2019-11-18 20:16:47 +00:00
unzip libiconv.zip
# add $USERPROFILE/tar/bin to path
echo $Env:USERPROFILE\tar\bin >> $Env:GITHUB_PATH
if: matrix.os == 'windows-latest'
- name: Check out code
2022-09-24 19:59:36 +00:00
uses: actions/checkout@v3
2019-11-18 20:16:47 +00:00
- name: Build with build.go
run: |
go run build.go
- name: Run local Tests
env:
RESTIC_TEST_FUSE: ${{ matrix.test_fuse }}
run: |
2022-11-11 20:58:57 +00:00
go test -cover ${{matrix.test_opts}} ./...
2019-11-18 20:16:47 +00:00
- name: Test cloud backends
env:
RESTIC_TEST_S3_KEY: ${{ secrets.RESTIC_TEST_S3_KEY }}
RESTIC_TEST_S3_SECRET: ${{ secrets.RESTIC_TEST_S3_SECRET }}
RESTIC_TEST_S3_REPOSITORY: ${{ secrets.RESTIC_TEST_S3_REPOSITORY }}
RESTIC_TEST_AZURE_ACCOUNT_NAME: ${{ secrets.RESTIC_TEST_AZURE_ACCOUNT_NAME }}
RESTIC_TEST_AZURE_ACCOUNT_KEY: ${{ secrets.RESTIC_TEST_AZURE_ACCOUNT_KEY }}
RESTIC_TEST_AZURE_REPOSITORY: ${{ secrets.RESTIC_TEST_AZURE_REPOSITORY }}
RESTIC_TEST_B2_ACCOUNT_ID: ${{ secrets.RESTIC_TEST_B2_ACCOUNT_ID }}
RESTIC_TEST_B2_ACCOUNT_KEY: ${{ secrets.RESTIC_TEST_B2_ACCOUNT_KEY }}
RESTIC_TEST_B2_REPOSITORY: ${{ secrets.RESTIC_TEST_B2_REPOSITORY }}
RESTIC_TEST_GS_REPOSITORY: ${{ secrets.RESTIC_TEST_GS_REPOSITORY }}
RESTIC_TEST_GS_PROJECT_ID: ${{ secrets.RESTIC_TEST_GS_PROJECT_ID }}
GOOGLE_PROJECT_ID: ${{ secrets.RESTIC_TEST_GS_PROJECT_ID }}
RESTIC_TEST_GS_APPLICATION_CREDENTIALS_B64: ${{ secrets.RESTIC_TEST_GS_APPLICATION_CREDENTIALS_B64 }}
RESTIC_TEST_OS_AUTH_URL: ${{ secrets.RESTIC_TEST_OS_AUTH_URL }}
RESTIC_TEST_OS_TENANT_NAME: ${{ secrets.RESTIC_TEST_OS_TENANT_NAME }}
RESTIC_TEST_OS_USERNAME: ${{ secrets.RESTIC_TEST_OS_USERNAME }}
RESTIC_TEST_OS_PASSWORD: ${{ secrets.RESTIC_TEST_OS_PASSWORD }}
RESTIC_TEST_OS_REGION_NAME: ${{ secrets.RESTIC_TEST_OS_REGION_NAME }}
RESTIC_TEST_SWIFT: ${{ secrets.RESTIC_TEST_SWIFT }}
# fail if any of the following tests cannot be run
RESTIC_TEST_DISALLOW_SKIP: "restic/backend/rest.TestBackendREST,\
restic/backend/sftp.TestBackendSFTP,\
restic/backend/s3.TestBackendMinio,\
restic/backend/rclone.TestBackendRclone,\
restic/backend/s3.TestBackendS3,\
restic/backend/swift.TestBackendSwift,\
restic/backend/b2.TestBackendB2,\
restic/backend/gs.TestBackendGS,\
restic/backend/azure.TestBackendAzure"
run: |
# prepare credentials for Google Cloud Storage tests in a temp file
export GOOGLE_APPLICATION_CREDENTIALS=$(mktemp --tmpdir restic-gcs-auth-XXXXXXX)
echo $RESTIC_TEST_GS_APPLICATION_CREDENTIALS_B64 | base64 -d > $GOOGLE_APPLICATION_CREDENTIALS
go test -cover -parallel 4 ./internal/backend/...
2021-01-03 09:28:57 +00:00
# only run cloud backend tests for pull requests from and pushes to our
# own repo, otherwise the secrets are not available
# Skip for Dependabot pull requests as these are run without secrets
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#responding-to-events
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && (github.actor != 'dependabot[bot]') && matrix.test_cloud_backends
2019-11-18 20:16:47 +00:00
- name: Check changelog files with calens
run: |
echo "install calens"
2022-03-20 10:36:45 +00:00
go install github.com/restic/calens@latest
2019-11-18 20:16:47 +00:00
echo "check changelog files"
calens
if: matrix.check_changelog
cross_compile:
strategy:
# ATTENTION: the list of architectures must be in sync with helpers/build-release-binaries/main.go!
matrix:
# run cross-compile in three batches parallel so the overall tests run faster
targets:
2023-01-28 19:19:07 +00:00
- "linux/386 linux/amd64 linux/arm linux/arm64 linux/ppc64le linux/mips linux/mipsle linux/mips64 linux/mips64le linux/riscv64 linux/s390x"
- "openbsd/386 openbsd/amd64 \
freebsd/386 freebsd/amd64 freebsd/arm \
aix/ppc64 \
darwin/amd64 darwin/arm64"
- "netbsd/386 netbsd/amd64 \
windows/386 windows/amd64 \
solaris/amd64"
2019-11-18 20:16:47 +00:00
env:
GOPROXY: https://proxy.golang.org
runs-on: ubuntu-latest
name: Cross Compile for ${{ matrix.targets }}
2019-11-18 20:16:47 +00:00
steps:
- name: Set up Go ${{ env.latest_go }}
uses: actions/setup-go@v4
2019-11-18 20:16:47 +00:00
with:
go-version: ${{ env.latest_go }}
2019-11-18 20:16:47 +00:00
- name: Install gox
run: |
go install github.com/mitchellh/gox@latest
- name: Check out code
2022-09-24 19:59:36 +00:00
uses: actions/checkout@v3
2019-11-18 20:16:47 +00:00
- name: Cross-compile with gox for ${{ matrix.targets }}
2019-11-18 20:16:47 +00:00
env:
GOFLAGS: "-trimpath"
GOX_ARCHS: "${{ matrix.targets }}"
2019-11-18 20:16:47 +00:00
run: |
mkdir build-output
gox -parallel 2 -verbose -osarch "$GOX_ARCHS" -output "build-output/{{.Dir}}_{{.OS}}_{{.Arch}}" ./cmd/restic
2020-11-29 17:47:00 +00:00
gox -parallel 2 -verbose -osarch "$GOX_ARCHS" -tags debug -output "build-output/{{.Dir}}_{{.OS}}_{{.Arch}}_debug" ./cmd/restic
2019-11-18 20:16:47 +00:00
lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Set up Go ${{ env.latest_go }}
uses: actions/setup-go@v4
with:
go-version: ${{ env.latest_go }}
2019-11-18 20:16:47 +00:00
- name: Check out code
2022-09-24 19:59:36 +00:00
uses: actions/checkout@v3
2019-11-18 20:16:47 +00:00
- name: golangci-lint
2022-09-24 19:59:36 +00:00
uses: golangci/golangci-lint-action@v3
2019-11-18 20:16:47 +00:00
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
2023-03-12 11:05:59 +00:00
version: v1.51
2019-11-18 20:16:47 +00:00
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
2023-03-12 11:02:22 +00:00
args: --verbose --timeout 10m
# only run golangci-lint for pull requests, otherwise ALL hints get
# reported. We need to slowly address all issues until we can enable
# linting the master branch :)
if: github.event_name == 'pull_request'
- name: Check go.mod/go.sum
run: |
echo "check if go.mod and go.sum are up to date"
go mod tidy
git diff --exit-code go.mod go.sum
2021-09-20 12:19:01 +00:00
docker:
name: docker
runs-on: ubuntu-latest
steps:
- name: Check out code
2022-09-24 19:59:36 +00:00
uses: actions/checkout@v3
2021-09-20 12:19:01 +00:00
- name: Docker meta
id: meta
2022-09-24 19:59:36 +00:00
uses: docker/metadata-action@v4
2021-09-20 12:19:01 +00:00
with:
# list of Docker images to use as base name for tags
images: |
restic/restic
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
2022-09-24 19:59:36 +00:00
uses: docker/setup-qemu-action@v2
2021-09-20 12:19:01 +00:00
- name: Set up Docker Buildx
2022-09-24 19:59:36 +00:00
uses: docker/setup-buildx-action@v2
2021-09-20 12:19:01 +00:00
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
2021-09-20 12:19:01 +00:00
with:
push: false
context: .
file: docker/Dockerfile
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}