From f0c4eb9160ea8d63678597bb13373b8b2c74896e Mon Sep 17 00:00:00 2001 From: Frederic Leger Date: Fri, 3 Jan 2025 11:00:18 +0100 Subject: [PATCH] ci: add docker workflow --- .github/FUNDING.yml | 5 + .github/dependabot.yml | 34 +++++ .github/release-drafter.yml | 169 ++++++++++++++++++++++++ .github/workflows/clean-docker-tags.yml | 21 +++ .github/workflows/docker.yml | 43 ++++++ .github/workflows/go.yml | 16 ++- .github/workflows/release.yml | 56 ++++++++ build.sh | 2 + 8 files changed, 340 insertions(+), 6 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/clean-docker-tags.yml create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..3962297 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,5 @@ +# These are supported funding model platforms + +github: +- fredleger +patreon: webofmars diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..20409b9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,34 @@ +# .github/dependabot.yml +version: 2 +updates: + + - package-ecosystem: "github-actions" + directories: + - "/" + open-pull-requests-limit: 3 + labels: + - "github_actions" + schedule: + interval: "weekly" + day: friday + time: '04:00' + + - package-ecosystem: "docker" + directory: "/" + open-pull-requests-limit: 3 + labels: + - "docker" + schedule: + interval: "weekly" + day: friday + time: '04:10' + + - package-ecosystem: "gomod" + directory: "/" + open-pull-requests-limit: 3 + labels: + - "pip" + schedule: + interval: "weekly" + day: friday + time: '04:20' diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..efd5c9a --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,169 @@ +template: | + ## What's Changed + + $CHANGES + + ## Full Changelog + + - https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION +name-template: "Version $RESOLVED_VERSION" +tag-template: "$RESOLVED_VERSION" + +version-resolver: + major: + labels: + - "release-major" + minor: + labels: + - "release-minor" + patch: + labels: + - "release-patch" + default: patch + +categories: + - title: '๐Ÿš€ Features' + labels: + - 'feature' + - 'feat' + - title: '๐Ÿ› Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '๐Ÿงฐ Maintenance' + label: 'chore' + - title: '๐Ÿ“š Documentation' + label: 'docs' + - title: '๐Ÿงช Tests' + label: 'test' + - title: '๐Ÿท๏ธ Version Tags' + label: 'version' + - title: '๐Ÿ”– Release Tags' + label: 'release' + - title: '๐Ÿงฉ Dependencies' + label: 'dependencies' + - title: '๐Ÿ”’ Security' + label: 'security' + - title: '๐Ÿšจ Breaking Changes' + label: 'breaking' + - title: '๐Ÿงน Code Cleanup' + label: 'cleanup' + - title: '๐Ÿ”ง Config' + label: 'config' + - title: '๐Ÿ“ฆ Packages' + label: 'package' + - title: '๐Ÿ”ฅ Removals' + label: 'removal' + - title: '๐Ÿšง Work In Progress' + label: 'wip' + - title: '๐Ÿ”€ Merges' + label: 'merge' + - title: '๐ŸŽจ Style' + label: 'style' + - title: '๐Ÿ”Š Logging' + label: 'logging' + - title: '๐Ÿ”‡ Silence' + label: 'silence' + - title: '๐Ÿค– CI/CD' + label: 'ci' + +autolabeler: + - label: "release-major" + title: + - "/^BREAKING CHANGE:/" + - label: "release-minor" + title: + - "/^feat:/" + - "/^feat\\(.+\\):/" + - label: "feature" + title: + - "/^feat:/" + - "/^feat\\(.+\\):/" + - label: "fix" + title: + - "/^fix:/" + - "/^fix\\(.+\\):/" + - label: "ci" + title: + - "/^ci:/" + - "/^ci\\(.+\\):/" + - label: "chore" + title: + - "/^chore:/" + - "/^chore\\(.+\\):/" + - label: "docs" + title: + - "/^docs:/" + - "/^docs\\(.+\\):/" + - "/^doc:/" + - "/^doc\\(.+\\):/" + - label: "test" + title: + - "/^test:/" + - "/^test\\(.+\\):/" + - label: "version" + title: + - "/^version:/" + - "/^version\\(.+\\):/" + - label: "release" + title: + - "/^release:/" + - "/^release\\(.+\\):/" + - label: "dependencies" + title: + - "/^deps:/" + - "/^deps\\(.+\\):/" + - "/^dependencies:/" + - "/^dependencies\\(.+\\):/" + - label: "security" + title: + - "/^security:/" + - "/^security\\(.+\\):/" + - label: "breaking" + title: + - "/^breaking:/" + - "/^breaking\\(.+\\):/" + - "/^BREAKING CHANGE:/" + - label: "cleanup" + title: + - "/^cleanup:/" + - "/^cleanup\\(.+\\):/" + - "/^refactor:/" + - "/^refactor\\(.+\\):/" + - label: "config" + title: + - "/^config:/" + - "/^config\\(.+\\):/" + - label: "package" + title: + - "/^package:/" + - "/^package\\(.+\\):/" + - label: "removal" + title: + - "/^removal:/" + - "/^removal\\(.+\\):/" + - "/^remove:/" + - "/^remove\\(.+\\):/" + - label: "wip" + title: + - "/^wip:/" + - "/^wip\\(.+\\):/" + - label: "merge" + title: + - "/^merge:/" + - "/^merge\\(.+\\):/" + - label: "style" + title: + - "/^style:/" + - "/^style\\(.+\\):/" + - label: "logging" + title: + - "/^logging:/" + - "/^logging\\(.+\\):/" + - "/^log:/" + - "/^log\\(.+\\):/" + - label: "silence" + title: + - "/^silence:/" + - "/^silence\\(.+\\):/" diff --git a/.github/workflows/clean-docker-tags.yml b/.github/workflows/clean-docker-tags.yml new file mode 100644 index 0000000..3f840f7 --- /dev/null +++ b/.github/workflows/clean-docker-tags.yml @@ -0,0 +1,21 @@ +name: Prune pull requests images tags + +on: + workflow_dispatch: + push: + branches: [main] + +permissions: + contents: read + pull-requests: read + packages: write + id-token: write + +jobs: + main: + uses: hoverkraft-tech/ci-github-container/.github/workflows/prune-pull-requests-images-tags.yml@0.18.0 + with: + runs-on: '["ubuntu-24.04"]' + images: "mailrelay" + prune-cache-images: true + pull-request-tag-filter: "^pr-([0-9]+)(?:-|$)" diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..f7ae012 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,43 @@ +name: Docker build images + +on: + push: + branches: + - main + pull_request: + branches: [main] + merge_group: + workflow_call: + inputs: + tag: + description: "Tag Version (semver - x.x.x)" + type: string + required: false + outputs: + built-images: + value: ${{ jobs.docker-build-images.outputs.built-images }} + +permissions: + contents: read + issues: read + packages: write + pull-requests: read + id-token: write + +jobs: + docker-build-images: + uses: hoverkraft-tech/ci-github-container/.github/workflows/docker-build-images.yml@0.18.0 + secrets: + oci-registry-password: ${{ secrets.GITHUB_TOKEN }} + with: + runs-on: '["ubuntu-24.04"]' + images: | + [{ + "name": "mailrelay", + "dockerfile": "./Dockerfile", + "build-args": {}, + "platforms": [ + "linux/amd64", + "linux/arm64" + ] + }] diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8b4dafb..880ce65 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -6,23 +6,27 @@ name: Go on: push: branches: - - master + - main pull_request: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.23' - name: Build - run: go build -v ./... + run: | + cd $GITHUB_WORKSPACE/src + go build -v ./... - name: Test - run: go test -v ./... + run: | + cd $GITHUB_WORKSPACE/src + go test -v ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..520e570 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: ๐Ÿš€ Release + +on: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + + check-branches: + name: Check branches + runs-on: self-hosted + steps: + - name: Check branch + run: | + if [[ "${{ github.ref_name }}" != "${{ github.event.repository.default_branch }}" ]]; then + echo "This action can only be run on the ${{ github.event.repository.default_branch }} branch" + exit 1 + fi + + update_release_draft: + name: Draft a new release + # we want to publish a new tag only if ci succeeds + needs: check-branches + permissions: + contents: write + pull-requests: write + runs-on: self-hosted + outputs: + latestRelease: ${{ steps.update_release_draft.outputs.tag_name }} + steps: + # create a new release + - id: update_release_draft + uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + publish: true + disable-autolabeler: true + + ci: + needs: update_release_draft + name: Continuous Integration + uses: ./.github/workflows/docker.yml + with: + tag: ${{ needs.update_release_draft.outputs.latestRelease }} + permissions: + actions: write + contents: read + id-token: write + issues: read + packages: write + pull-requests: read + secrets: inherit diff --git a/build.sh b/build.sh index 2e63bb8..0048409 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,7 @@ #!/bin/bash +cd src + # build Linux echo building Linux... env GOOS=linux GOARCH=amd64 go build -o ./build/linux_amd64/mailrelay-linux-amd64