From 127c76d006399b2f4faf750e00dd5bbec328bd27 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 5 Mar 2025 22:18:02 +0100 Subject: [PATCH] Add workflows for CI --- .github/workflows/goreleaser.yml | 32 ++++++++++++ .github/workflows/image.yml | 84 ++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 25 ++++++++++ 3 files changed, 141 insertions(+) create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .github/workflows/image.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..f3f7a49 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,32 @@ +name: goreleaser + +on: + push: + tags: + - 'v*' # Add this line to trigger the workflow on tag pushes that match 'v*' + +permissions: + id-token: write + contents: read + +jobs: + goreleaser: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.22 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + version: '~> v2' + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml new file mode 100644 index 0000000..1f2bbac --- /dev/null +++ b/.github/workflows/image.yml @@ -0,0 +1,84 @@ +--- +name: 'build container images' +on: + push: + branches: + - main + tags: + - '*' +concurrency: + group: ci-image-${{ github.head_ref || github.ref }}-${{ github.repository }} + cancel-in-progress: true +jobs: + containerImages: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Prepare + id: prep + run: | + DOCKER_IMAGE=quay.io/mudler/LocalAgent + # Use branch name as default + VERSION=${GITHUB_REF#refs/heads/} + BINARY_VERSION=$(git describe --always --tags --dirty) + SHORTREF=${GITHUB_SHA::8} + # If this is git tag, use the tag name as a docker tag + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + fi + TAGS="${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${SHORTREF}" + # If the VERSION looks like a version number, assume that + # this is the most recent version of the image and also + # tag it 'latest'. + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + TAGS="$TAGS,${DOCKER_IMAGE}:latest" + fi + # Set output parameters. + echo ::set-output name=binary_version::${BINARY_VERSION} + echo ::set-output name=tags::${TAGS} + echo ::set-output name=docker_image::${DOCKER_IMAGE} + - name: Set up QEMU + uses: docker/setup-qemu-action@master + with: + platforms: all + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@master + + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@2a4836ac76fe8f5d0ee3a0d89aa12a80cc552ad3 + with: + images: quay.io/mudler/LocalAgent + tags: | + type=ref,event=branch,suffix=-{{date 'YYYYMMDDHHmmss'}} + type=semver,pattern={{raw}} + type=sha,suffix=-{{date 'YYYYMMDDHHmmss'}} + type=ref,event=branch + flavor: | + latest=auto + prefix= + suffix= + + - name: Build + uses: docker/build-push-action@v6 + with: + builder: ${{ steps.buildx.outputs.name }} + build-args: | + VERSION=${{ steps.prep.outputs.binary_version }} + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + #tags: ${{ steps.prep.outputs.tags }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..5ab55cd --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,25 @@ +name: Run Go Tests + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Run tests + run: | + make test + sudo mv coverage/coverage.txt coverage.txt + sudo chmod 777 coverage.txt + + # - name: Upload coverage to Codecov + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file