git » chasquid » commit 795f2a7

ci: Use Github Actions to run integration tests and push Docker images

author Alberto Bertogli
2022-11-13 11:33:56 UTC
committer Alberto Bertogli
2022-11-13 19:16:10 UTC
parent 948cee1ce16df4c5ac5a3218b291f1bee71eb412

ci: Use Github Actions to run integration tests and push Docker images

We're running against the usage limits in Gitlab CI (500), and Github
Actions should have more (2000).

So this patch replaces Gitlab CI with Github actions for running
integration tests, and build and push Docker images (to Dockerhub and
Gitlab registry).

We'll see how the usage levels are in a few months.

.github/workflows/docker.yml +74 -0
.github/workflows/gotests.yml +39 -0
.gitlab-ci.yml +0 -102
README.md +1 -2
test/README.md +7 -10

diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
new file mode 100644
index 0000000..b17872b
--- /dev/null
+++ b/.github/workflows/docker.yml
@@ -0,0 +1,74 @@
+name: "docker"
+
+on:
+  push:
+    branches: [ "master", "next" ]
+  pull_request:
+    # The branches below must be a subset of the branches above
+    branches: [ "master", "next" ]
+  schedule:
+    - cron: '29 21 * * 6'
+
+env:
+  HAS_DOCKER: ${{ secrets.DOCKER_REGISTRY_USER != '' }}
+  HAS_GITLAB: ${{ secrets.GITLAB_REGISTRY_USER != '' }}
+
+jobs:
+  integration:
+    runs-on: ubuntu-latest
+    timeout-minutes: 5
+    steps:
+      - uses: actions/checkout@v3
+      - name: Docker info (for debugging)
+        run: docker info
+      - name: Build test image
+        run: docker build -t chasquid-test -f test/Dockerfile .
+      - name: Run tests
+        run: docker run --name test1 chasquid-test  make test
+
+  public-image:
+    runs-on: ubuntu-latest
+    timeout-minutes: 15
+    needs: integration
+    if: github.event_name == 'push'
+    steps:
+      - uses: actions/checkout@v3
+      - name: Build
+        run: docker build -t chasquid -f docker/Dockerfile .
+
+      # Push it to Dockerhub.
+      - name: Dockerhub login
+        if: env.HAS_DOCKER
+        uses: docker/login-action@v2
+        with:
+          username: ${{ secrets.DOCKER_REGISTRY_USER }}
+          password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
+      - name: Dockerhub push
+        if: env.HAS_DOCKER
+        run: |
+          docker tag chasquid index.docker.io/${{ secrets.DOCKER_REGISTRY_USER }}/chasquid:$GITHUB_REF_NAME
+          docker push index.docker.io/${{ secrets.DOCKER_REGISTRY_USER }}/chasquid:$GITHUB_REF_NAME
+      - name: Dockerhub tag latest
+        if: env.HAS_DOCKER && env.GITHUB_REF_NAME == 'master'
+        run: |
+          docker tag chasquid index.docker.io/${{ secrets.DOCKER_REGISTRY_USER }}/chasquid:latest
+          docker push index.docker.io/${{ secrets.DOCKER_REGISTRY_USER }}/chasquid:latest
+
+      # Push it to Gitlab.
+      - name: Gitlab login
+        if: env.HAS_GITLAB
+        uses: docker/login-action@v2
+        with:
+          registry: registry.gitlab.com
+          username: ${{ secrets.GITLAB_REGISTRY_USER }}
+          password: ${{ secrets.GITLAB_REGISTRY_TOKEN }}
+      - name: Gitlab push
+        if: env.HAS_GITLAB
+        run: |
+          docker tag chasquid registry.gitlab.com/albertito/chasquid:$GITHUB_REF_NAME
+          docker push registry.gitlab.com/albertito/chasquid:$GITHUB_REF_NAME
+      - name: Gitlab tag latest
+        if: env.HAS_GITLAB && env.GITHUB_REF_NAME == 'master'
+        run: |
+          docker tag chasquid registry.gitlab.com/albertito/chasquid:latest
+          docker push registry.gitlab.com/albertito/chasquid:latest
diff --git a/.github/workflows/gotests.yml b/.github/workflows/gotests.yml
new file mode 100644
index 0000000..21aa970
--- /dev/null
+++ b/.github/workflows/gotests.yml
@@ -0,0 +1,39 @@
+name: "gotests"
+
+on:
+  push:
+    branches: [ "master", "next" ]
+  pull_request:
+    # The branches below must be a subset of the branches above
+    branches: [ "master", "next" ]
+  schedule:
+    - cron: '29 21 * * 6'
+
+jobs:
+  oldest_supported:
+    runs-on: ubuntu-latest
+    timeout-minutes: 5
+    steps:
+      - uses: actions/checkout@v3
+      - uses: actions/setup-go@v3
+        with:
+          go-version-file: 'go.mod'
+      - name: normal tests
+        run: go test ./...
+      - name: race tests
+        run: go test -race ./...
+
+  latest:
+    runs-on: ubuntu-latest
+    timeout-minutes: 5
+    steps:
+      - uses: actions/checkout@v3
+      - uses: actions/setup-go@v3
+        with:
+          go-version: "1.x"
+          check-latest: true
+      - name: normal tests
+        run: go test ./...
+      - name: race tests
+        run: go test -race ./...
+
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
deleted file mode 100644
index 6409c94..0000000
--- a/.gitlab-ci.yml
+++ /dev/null
@@ -1,102 +0,0 @@
-
-stages:
-  - test
-  - image
-
-# Go tests, on various Go versions.
-.golang_template: &golang
-  stage: test
-  before_script:
-    - useradd --create-home --user-group testing
-    - chown -R testing:testing $GOPATH/ .
-  script:
-    - su testing -c "go mod download"
-    - su testing -c "go get ./..."
-    - su testing -c "make all"
-    - su testing -c "go test ./..."
-    - su testing -c "go test -race ./..."
-
-golang_1.17:
-  <<: *golang
-  image: golang:1.17    # Oldest supported Go version.
-
-golang_latest:
-  <<: *golang
-  image: golang:latest
-
-# Integration test, using the module versions from the repository.
-integration_stable:
-  stage: test
-  image: docker:stable
-  services:
-    - docker:dind
-  script:
-    - docker info
-    - docker build -t chasquid-test -f test/Dockerfile .
-    - docker run chasquid-test  env
-    - docker run --name test1 chasquid-test  make test
-  after_script:
-    - docker cp test1:/go/src/blitiri.com.ar/go/chasquid docker-out/
-  artifacts:
-    when: always
-    expire_in: 1 hour
-    paths:
-      - docker-out/
-
-
-# Integration test, using the latest module versions.
-integration_latest:
-  stage: test
-  image: docker:stable
-  services:
-    - docker:dind
-  script:
-    - docker info
-    - docker build -t chasquid-test --build-arg GO_GET_ARGS="-u=patch" -f test/Dockerfile .
-    - docker run chasquid-test  env
-    - docker run --name test1 chasquid-test  make test
-  after_script:
-    - docker cp test1:/go/src/blitiri.com.ar/go/chasquid docker-out/
-  artifacts:
-    when: always
-    expire_in: 1 hour
-    paths:
-      - docker-out/
-
-# Build docker image, upload to gitlab registry.
-gitlab:
-  stage: image
-  rules:
-    - if: '$CI_REGISTRY_IMAGE'
-  image: docker:stable
-  services:
-    - docker:dind
-  script:
-    - docker info
-    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
-    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME -f docker/Dockerfile .
-    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
-    - |
-      if [ $CI_COMMIT_REF_NAME == master ]; then
-          docker tag $CI_REGISTRY_IMAGE:master $CI_REGISTRY_IMAGE:latest
-          docker push $CI_REGISTRY_IMAGE:latest
-      fi
-
-# Build docker image, upload to dockerhub registry.
-dockerhub:
-  stage: image
-  rules:
-    - if: '$DOCKER_REGISTRY_USER'
-  image: docker:stable
-  services:
-    - docker:dind
-  script:
-    - docker info
-    - docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASSWORD docker.io
-    - docker build -t index.docker.io/albertito/chasquid:$CI_COMMIT_REF_NAME -f docker/Dockerfile .
-    - docker push index.docker.io/albertito/chasquid:$CI_COMMIT_REF_NAME
-    - |
-      if [ $CI_COMMIT_REF_NAME == master ]; then
-          docker tag index.docker.io/albertito/chasquid:master index.docker.io/albertito/chasquid:latest
-          docker push index.docker.io/albertito/chasquid:latest
-      fi
diff --git a/README.md b/README.md
index 5d4cf9d..fdcf839 100644
--- a/README.md
+++ b/README.md
@@ -9,8 +9,7 @@ It is designed mainly for individuals and small groups.
 It's written in [Go](https://golang.org), and distributed under the
 [Apache license 2.0](http://en.wikipedia.org/wiki/Apache_License).
 
-[![Gitlab CI status](https://gitlab.com/albertito/chasquid/badges/master/pipeline.svg)](https://gitlab.com/albertito/chasquid/pipelines)
-[![Cirrus-CI Status](https://api.cirrus-ci.com/github/albertito/chasquid.svg?branch=next)](https://cirrus-ci.com/github/albertito/chasquid)
+[![Github status](https://img.shields.io/github/checks-status/albertito/chasquid/master)](https://github.com/albertito/chasquid/actions)
 [![Go Report Card](https://goreportcard.com/badge/github.com/albertito/chasquid)](https://goreportcard.com/report/github.com/albertito/chasquid)
 [![Coverage](https://img.shields.io/badge/coverage-next-brightgreen.svg)](https://blitiri.com.ar/p/chasquid/coverage.html)  
 [![Docs](https://img.shields.io/badge/docs-reference-blue.svg)](https://blitiri.com.ar/p/chasquid/)
diff --git a/test/README.md b/test/README.md
index 2bd2750..f3368f7 100644
--- a/test/README.md
+++ b/test/README.md
@@ -93,16 +93,13 @@ constrained or non supported environments.
 There are two sets of automated tests which are run on every commit to
 upstream, and weekly:
 
-* [GitLab CI](https://gitlab.com/albertito/chasquid/commits/master),
-  configured in the `.gitlab-ci.yml` file, runs the Go tests and the
-  integration tests (using [docker](#docker)).  
-  The integration tests are run twice: once against the dependencies listed in
-  `go.mod`, and once against the latest version of the dependencies.
-  It also builds the [public Docker images](docker.md).
-
-* [Cirrus CI](https://gitlab.com/albertito/chasquid/pipelines),
-  configured in the `.cirrus.yml` file, runs Go tests on FreeBSD, and a
-  comprehensive linter.
+* [Github Actions](https://github.com/albertito/chasquid/actions),
+  configured in the `.github` directory, runs the Go tests, the integration
+  tests, checks for vulnerabilities, and finally
+  also builds the [public Docker images](docker.md).
+
+* [Cirrus CI](https://cirrus-ci.com/github/albertito/chasquid),
+  configured in the `.cirrus.yml` file, runs Go tests on FreeBSD.
 
 
 ## Coverage