Skip to content

Commit

Permalink
chore(ci): Switch to github workflows (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
znerol authored Dec 7, 2023
1 parent 854b59a commit eff8f36
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 94 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/container-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Build and push container image

# yamllint disable-line rule:truthy
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
container-image:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64${{ github.event_name != 'pull_request' && ', linux/arm64' || '' }}
tags: "${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}-gh-build-${{ github.run_id }}"
build-args: |
build_log_label=GH Build #${{ github.run_number }}
build_log_url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
42 changes: 42 additions & 0 deletions .github/workflows/dockerhub-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Tag latest container image

# yamllint disable-line rule:truthy
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
latest-image:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract Version (Patch)
run: echo "VERSION_PATCH=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV

- name: Extract Version (Minor)
run: echo "VERSION_MINOR=${VERSION_PATCH%.*}" >> $GITHUB_ENV

- name: Extract Version (Major)
run: echo "VERSION_MAJOR=${VERSION_MINOR%.*}" >> $GITHUB_ENV

- name: Tag docker image
run: >-
docker buildx imagetools create ${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}-gh-build-${{ github.run_id }}
--tag ${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}-${{ env.VERSION_PATCH}}
--tag ${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}-${{ env.VERSION_MINOR}}
--tag ${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}-${{ env.VERSION_MAJOR}}
--tag ${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}
28 changes: 28 additions & 0 deletions .github/workflows/dockerhub-rolling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Tag rolling container image

# yamllint disable-line rule:truthy
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
rolling-image:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Tag docker image
run: docker buildx imagetools create ${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}-gh-build-${{ github.run_id }} --tag ${{ vars.IMAGE_NAME }}:${{ vars.IMAGE_VARIANT }}-rolling
34 changes: 34 additions & 0 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Create github release

# yamllint disable-line rule:truthy
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
release-notes:
runs-on: ubuntu-latest

permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"

- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
42 changes: 42 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Run integration test on container image

# yamllint disable-line rule:truthy
on:
workflow_call:
secrets:
PRIVATE_SSH_KEY:
required: true
PRIVATE_DIGITALOCEAN_TOKEN:
required: true
PRIVATE_LEGO_ACCOUNT_KEY:
required: true

env:
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
IMAGE_VARIANT: ${{ vars.IMAGE_VARIANT }}
IMAGE_BUILD_ID: "${{ vars.IMAGE_VARIANT }}-gh-build-${{ github.run_id }}"
PRIVATE_SSH_KEY: "${{ secrets.PRIVATE_SSH_KEY }}"
PRIVATE_DIGITALOCEAN_TOKEN: "${{ secrets.PRIVATE_DIGITALOCEAN_TOKEN }}"
PRIVATE_LEGO_ACCOUNT_KEY: "${{ secrets.PRIVATE_LEGO_ACCOUNT_KEY }}"
DOCKER_COMPOSE_ARGS: >-
-f integration-test/docker-compose.yml
-f integration-test/docker-compose.github.yml
-f integration-test/docker-compose.test-${{ vars.IMAGE_VARIANT }}.github.yml
jobs:
integration-test:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up integration test
run: docker-compose ${{ env.DOCKER_COMPOSE_ARGS }} build

- name: Run integration test
run: docker-compose ${{ env.DOCKER_COMPOSE_ARGS }} run sut
16 changes: 16 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Integration Tests (Pull Request)

# yamllint disable-line rule:truthy
on:
pull_request:

jobs:
build:
uses: ./.github/workflows/container-image.yml
secrets: inherit

run:
needs: build
uses: ./.github/workflows/integration-test.yml
secrets: inherit
23 changes: 23 additions & 0 deletions .github/workflows/on-push-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Publish Rolling Image (Push develop)

# yamllint disable-line rule:truthy
on:
push:
branches:
- develop

jobs:
build:
uses: ./.github/workflows/container-image.yml
secrets: inherit

run:
needs: build
uses: ./.github/workflows/integration-test.yml
secrets: inherit

tag:
needs: run
uses: ./.github/workflows/dockerhub-rolling.yml
secrets: inherit
23 changes: 23 additions & 0 deletions .github/workflows/on-push-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Publish Latest Image (Push latest)

# yamllint disable-line rule:truthy
on:
push:
branches:
- latest

jobs:
build:
uses: ./.github/workflows/container-image.yml
secrets: inherit

run:
needs: build
uses: ./.github/workflows/integration-test.yml
secrets: inherit

release:
needs: run
uses: ./.github/workflows/github-release.yml
secrets: inherit
22 changes: 22 additions & 0 deletions .github/workflows/on-release-published.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Publish Latest Image (Release Published)

# yamllint disable-line rule:truthy
on:
release:
types: [published]

jobs:
build:
uses: ./.github/workflows/container-image.yml
secrets: inherit

run:
needs: build
uses: ./.github/workflows/integration-test.yml
secrets: inherit

tag:
needs: run
uses: ./.github/workflows/dockerhub-latest.yml
secrets: inherit
15 changes: 15 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"branches": [
"latest"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/github",
{
"draftRelease": true
}
]
]
}
7 changes: 0 additions & 7 deletions .releaserc.yml

This file was deleted.

86 changes: 0 additions & 86 deletions .travis.yml

This file was deleted.

Loading

0 comments on commit eff8f36

Please sign in to comment.