Skip to content

Commit

Permalink
update/cicd (#231)
Browse files Browse the repository at this point in the history
* redo github workflows; simplify make

* fix workflow

* fix buildx and test results

* add missing checkout for job

* fix release workflow

* use local registry for testing

* run docker from image tar
  • Loading branch information
alexei-led authored Jan 10, 2023
1 parent f3f7422 commit 0f5ba80
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 987 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.idea
.vscode
.github
.test

.gitignore
.env
Expand Down
139 changes: 47 additions & 92 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,117 +1,72 @@
name: "Continuous Integration"
name: "Build and Test"

on:
push:
branches:
- '*'
tags:
- '*'
pull_request:
paths-ignore:
- 'docs/**'
- 'deploy/**'
- 'examples/**'
- '*.md'
pull_request:
branches:
- '*'

jobs:

buildx:
test:
name: "lint and test"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
permissions:
checks: write
pull-requests: write

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker buildx
id: buildx
uses: docker/setup-buildx-action@v1
steps:
- name: checkout
uses: actions/checkout@v3

- name: Cache Docker layers
uses: actions/cache@v2
id: cache
- name: setup Go
uses: actions/setup-go@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
go-version: 1.19

- name: Build, lint and test
env:
DOCKER_ORG: ${{ secrets.DOCKER_ORG }}
uses: docker/build-push-action@v2
with:
file: docker/Dockerfile
context: .
build-args: |
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}
VCS_COMMIT_ID=${{ github.sha }}
VCS_BRANCH_NAME=${{ steps.tagger.outputs.tag }}
VCS_SLUG=${{ github.repository }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
load: true
tags: pumba/build-and-test
target: build-and-test
- name: lint and test
shell: sh
run: |
make lint
make test-coverage
- name: Build integration tests image
env:
DOCKER_ORG: ${{ secrets.DOCKER_ORG }}
uses: docker/build-push-action@v2
- name: publish test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
file: docker/Dockerfile
context: .
build-args: |
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}
VCS_COMMIT_ID=${{ github.sha }}
VCS_BRANCH_NAME=${{ steps.tagger.outputs.tag }}
VCS_SLUG=${{ github.repository }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
load: true
tags: pumba/integration-tests
target: integration-tests
junit_files: ".cover/tests.xml"

- name: Run integration tests
run: |
docker run -i --rm --name integration-tests -v /var/run/docker.sock:/var/run/docker.sock pumba/integration-tests
- name: upload coverage
uses: codecov/codecov-action@v3
with:
files: ".cover/coverage.xml"

- name: Upload coverage report
run: |
CI_BUILD_URL=https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks
docker run -i --rm --name upload-coverage -e CI_BUILD_URL=${CI_BUILD_URL} -e CI_BUILD_ID=${RUNNER_TRACKING_ID} pumba/build-and-test
integration:
name: "integration tests"
runs-on: ubuntu-latest

- name: Decide on tag
id: tagger
run: |
tag=$(echo "${{ github.ref }}" | sed -e 's/^refs\/heads\///g' -e 's/^refs\/tags\///g' -e 's/^refs\/pull\///g' -e 's/\/merge$//g' | sed -e 's/master/latest/g')
echo "::set-output name=tag::${tag}"
echo "::debug::docker image tag ${tag}"
steps:
- name: checkout
uses: actions/checkout@v3

- name: Login to DockerHub
uses: docker/login-action@v1
- name: setup buildx
uses: docker/setup-buildx-action@v2
with:
username: ${{ secrets.DOCKER_ACCOUNT }}
password: ${{ secrets.DOCKER_TOKEN }}
driver-opts: network=host

- name: Build and push Docker image
if: github.event_name != 'pull_request'
env:
DOCKER_ORG: ${{ secrets.DOCKER_ORG }}
uses: docker/build-push-action@v2
- name: build image
uses: docker/build-push-action@v3
with:
build-args: SKIP_TESTS=true
file: docker/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
build-args: |
CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}
VCS_COMMIT_ID=${{ github.sha }}
VCS_BRANCH_NAME=${{ steps.tagger.outputs.tag }}
VCS_SLUG=${{ github.repository }}
SKIP_TESTS=true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
push: true
tags: ${{ secrets.DOCKER_ORG }}/pumba:${{ steps.tagger.outputs.tag }}
tags: pumba:test
target: integration-tests
outputs: type=docker,dest=/tmp/image.tar

- name: integration tests
run: |
docker load -i /tmp/image.tar
docker run -i --rm --name integration-tests -v /var/run/docker.sock:/var/run/docker.sock pumba:test
33 changes: 18 additions & 15 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ on:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '0 17 * * 5'

jobs:
analyze:
name: Analyze
CodeQL-Build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: [ 'go' ]
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
permissions:
# required for all workflows
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand All @@ -38,14 +41,14 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
languages: go

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -59,4 +62,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
101 changes: 73 additions & 28 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,94 @@
name: "Release to GitHub"
name: "Release"

on:
workflow_dispatch:
push:
branches:
- 'master'
- master
tags:
- '[0-9]+.[0-9]+.[0-9]+'
paths-ignore:
- 'docs/**'
- 'deploy/**'
- 'examples/**'
- 'test/**'
- '*.md'
- '*.yaml'

jobs:

release:
build:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
container: golang:1.19-alpine

- name: Set up Docker buildx
id: buildx
uses: docker/setup-buildx-action@v1
steps:
- name: checkout
uses: actions/checkout@v3

- name: Decide on tag
id: tagger
- name: build
shell: sh
env:
GOPROXY: https://proxy.golang.org
CGO_ENABLED: 0
run: |
tag=$(echo "${{ github.ref }}" | sed -e 's/^refs\/heads\///g' -e 's/^refs\/tags\///g' -e 's/^refs\/pull\///g' -e 's/\/merge$//g' | sed -e 's/master/latest/g')
echo "::set-output name=tag::${tag}"
echo "::debug::docker image tag ${tag}"
apk --update add ca-certificates tzdata make git bash
make release
create-release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
name: release
needs: [ build ]
runs-on: ubuntu-latest

steps:
- name: tag
id: get_tag
run: echo ::set-output name=git_tag::${GITHUB_REF/refs\/tags\//}

- name: changelog
id: build_changelog
uses: mikepenz/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: release
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.get_tag.outputs.git_tag }}
tag_name: ${{ steps.get_tag.outputs.git_tag }}
body: ${{steps.build_changelog.outputs.changelog}}
files: |
.bin/*
push:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
name: push
runs-on: ubuntu-latest

steps:
- name: checkout
uses: actions/checkout@v3

- name: get tag
id: get_tag
run: echo ::set-output name=git_tag::${GITHUB_REF/refs\/tags\//}

- name: setup QEMU
uses: docker/setup-qemu-action@v2

- name: setup buildx
uses: docker/setup-buildx-action@v2

- name: login to registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_ACCOUNT }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Release to GitHub
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v2
- name: build and push
uses: docker/build-push-action@v3
with:
file: docker/Dockerfile
context: .
build-args: |
RELEASE=true
RELEASE_TAG=${{ steps.tagger.outputs.tag }}
RELEASE_TOKEN=${{ secrets.RELEASE_TOKEN }}
TAG_MESSAGE="Draft Release"
GITHUB_TOKEN=${{ secrets.RELEASE_TOKEN }}
VCS_COMMIT_ID=${{ github.sha }}
VCS_BRANCH_NAME=${{ steps.tagger.outputs.tag }}
VCS_SLUG=${{ github.repository }}
target: github-release
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_ORG }}/pumba:${{ steps.get_tag.outputs.git_tag }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.bin
.env
.in
/.gtm/
.test

**/.DS_Store
**/debug
Expand Down
File renamed without changes.
Loading

0 comments on commit 0f5ba80

Please sign in to comment.