Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 148 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,161 @@
---
name: ci

on:
pull_request:
push:
branches:
- main

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
# Keep compatibility with existing branch protection rules
test:
if: ${{ (github.event_name == 'pull_request' || github.ref_name == 'main') && github.actor != 'dependabot[bot]' }}
uses: ./.github/workflows/.test.yml
push-docker:

# New efficient build jobs
lint:
runs-on: ubuntu-24.04
steps:
- name: ci/checkout-repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
with:
go-version-file: go.mod

- name: ci/check-modules
run: make check-modules

# Build AMD64 image (fast native build)
build-amd64:
runs-on: ubuntu-24.04
needs: [test, lint]
if: ${{ (github.event_name == 'pull_request' || github.ref_name == 'main') && github.actor != 'dependabot[bot]' }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Log in to Docker Hub
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build AMD64 image (temp tag)
run: |
docker buildx build \
--platform linux/amd64 \
--build-arg DOCKER_BUILD_IMAGE=golang:1.24 \
--build-arg DOCKER_BASE_IMAGE=alpine:3.20 \
. -f build/Dockerfile -t mattermost/elrond:temp-${{ github.sha }}-amd64 \
--push
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}

# Build ARM64 image (fast native build)
build-arm64:
runs-on: ubuntu-24.04-arm
needs: [test, lint]
if: ${{ (github.event_name == 'pull_request' || github.ref_name == 'main') && github.actor != 'dependabot[bot]' }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Log in to Docker Hub
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build ARM64 image (temp tag)
run: |
docker buildx build \
--platform linux/arm64 \
--build-arg DOCKER_BUILD_IMAGE=golang:1.24 \
--build-arg DOCKER_BASE_IMAGE=alpine:3.20 \
. -f build/Dockerfile -t mattermost/elrond:temp-${{ github.sha }}-arm64 \
--push
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}

# Create unified multi-arch manifest (clean tag)
create-manifest:
runs-on: ubuntu-24.04
needs: [build-amd64, build-arm64]
if: ${{ (github.event_name == 'pull_request' || github.ref_name == 'main') && github.actor != 'dependabot[bot]' }}
uses: ./.github/workflows/.docker-push.yml
with:
is_pr: "${{ github.ref != 'refs/heads/main' }}"
secrets: inherit
needs: [test]
steps:
- name: Log in to Docker Hub
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create unified multi-arch manifest
run: |
# Determine clean tag
if [ "${{ github.event_name }}" = "pull_request" ]; then
CLEAN_TAG="pr-${{ github.event.number }}"
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
# Create timestamp-based tag for main merges (format: test-YYYYMMDD.HHMMSS)
TIMESTAMP=$(date -u +"%Y%m%d.%H%M%S")
CLEAN_TAG="test-${TIMESTAMP}"
else
CLEAN_TAG="${{ github.ref_name }}"
fi

# Create manifest from temp tags
docker manifest create mattermost/elrond:${CLEAN_TAG} \
--amend mattermost/elrond:temp-${{ github.sha }}-amd64 \
--amend mattermost/elrond:temp-${{ github.sha }}-arm64

# Push the clean unified tag
docker manifest push mattermost/elrond:${CLEAN_TAG}

echo "βœ… Clean unified multi-arch tag: mattermost/elrond:${CLEAN_TAG}"

# Cleanup temp tags using Docker Hub API
echo "πŸ—‘οΈ Cleaning up temp tags from Docker Hub..."

# Delete temp tags using Docker Hub API
TEMP_AMD64_TAG="temp-${{ github.sha }}-amd64"
TEMP_ARM64_TAG="temp-${{ github.sha }}-arm64"

# Get Docker Hub API token
DOCKER_HUB_TOKEN=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"username": "${{ secrets.DOCKERHUB_USERNAME }}", "password": "${{ secrets.DOCKERHUB_CLEANUP_TOKEN }}"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)

# Delete AMD64 temp tag
curl -X DELETE \
-H "Authorization: JWT ${DOCKER_HUB_TOKEN}" \
"https://hub.docker.com/v2/repositories/mattermost/elrond/tags/${TEMP_AMD64_TAG}/" \
&& echo "βœ… Deleted AMD64 temp tag" || echo "⚠️ AMD64 temp tag not found or already deleted"

# Delete ARM64 temp tag
curl -X DELETE \
-H "Authorization: JWT ${DOCKER_HUB_TOKEN}" \
"https://hub.docker.com/v2/repositories/mattermost/elrond/tags/${TEMP_ARM64_TAG}/" \
&& echo "βœ… Deleted ARM64 temp tag" || echo "⚠️ ARM64 temp tag not found or already deleted"

echo "βœ… Temp tags cleaned up from Docker Hub"

# Store the clean tag for potential future steps
echo "IMAGE_TAG=${CLEAN_TAG}" >> $GITHUB_ENV
174 changes: 163 additions & 11 deletions .github/workflows/publish-gihub-release.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,182 @@
---
name: release

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+*

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-24.04
steps:
- name: ci/checkout-repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
with:
go-version-file: go.mod

- name: ci/check-style
run: make check-style

- name: ci/check-modules
run: make check-modules

test:
uses: ./.github/workflows/.test.yml
push-docker:
uses: ./.github/workflows/.docker-push.yml
with:
is_pr: false
secrets: inherit
needs: [test]
runs-on: ubuntu-24.04
steps:
- name: ci/checkout-repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
with:
go-version-file: go.mod

- name: ci/unit-test
run: make unittest

# Build AMD64 image (fast native build)
build-amd64:
runs-on: ubuntu-24.04
needs: [test, lint]
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Log in to Docker Hub
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build AMD64 image (temp tag)
run: |
docker buildx build \
--platform linux/amd64 \
--build-arg DOCKER_BUILD_IMAGE=golang:1.24 \
--build-arg DOCKER_BASE_IMAGE=alpine:3.20 \
. -f build/Dockerfile -t mattermost/elrond:temp-${{ github.sha }}-amd64 \
--push
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}

# Build ARM64 image (fast native build)
build-arm64:
runs-on: ubuntu-24.04-arm
needs: [test, lint]
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Log in to Docker Hub
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build ARM64 image (temp tag)
run: |
docker buildx build \
--platform linux/arm64 \
--build-arg DOCKER_BUILD_IMAGE=golang:1.24 \
--build-arg DOCKER_BASE_IMAGE=alpine:3.20 \
. -f build/Dockerfile -t mattermost/elrond:temp-${{ github.sha }}-arm64 \
--push
env:
DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }}

# Create unified multi-arch manifest (versioned tags)
create-manifest:
runs-on: ubuntu-24.04
needs: [build-amd64, build-arm64]
steps:
- name: Log in to Docker Hub
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Create unified multi-arch manifest
run: |
# Use the full version tag (including 'v' prefix)
VERSION_TAG="${{ github.ref_name }}"

# Create manifest for version tag and latest
docker manifest create mattermost/elrond:${VERSION_TAG} \
--amend mattermost/elrond:temp-${{ github.sha }}-amd64 \
--amend mattermost/elrond:temp-${{ github.sha }}-arm64

docker manifest create mattermost/elrond:latest \
--amend mattermost/elrond:temp-${{ github.sha }}-amd64 \
--amend mattermost/elrond:temp-${{ github.sha }}-arm64

# Push the unified tags
docker manifest push mattermost/elrond:${VERSION_TAG}
docker manifest push mattermost/elrond:latest

echo "βœ… Clean unified multi-arch tags: mattermost/elrond:${VERSION_TAG} and mattermost/elrond:latest"

# Cleanup temp tags using Docker Hub API
echo "πŸ—‘οΈ Cleaning up temp tags from Docker Hub..."

# Delete temp tags using Docker Hub API
TEMP_AMD64_TAG="temp-${{ github.sha }}-amd64"
TEMP_ARM64_TAG="temp-${{ github.sha }}-arm64"

# Get Docker Hub API token
DOCKER_HUB_TOKEN=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"username": "${{ secrets.DOCKERHUB_USERNAME }}", "password": "${{ secrets.DOCKERHUB_CLEANUP_TOKEN }}"}' \
https://hub.docker.com/v2/users/login/ | jq -r .token)

# Delete AMD64 temp tag
curl -X DELETE \
-H "Authorization: JWT ${DOCKER_HUB_TOKEN}" \
"https://hub.docker.com/v2/repositories/mattermost/elrond/tags/${TEMP_AMD64_TAG}/" \
&& echo "βœ… Deleted AMD64 temp tag" || echo "⚠️ AMD64 temp tag not found or already deleted"

# Delete ARM64 temp tag
curl -X DELETE \
-H "Authorization: JWT ${DOCKER_HUB_TOKEN}" \
"https://hub.docker.com/v2/repositories/mattermost/elrond/tags/${TEMP_ARM64_TAG}/" \
&& echo "βœ… Deleted ARM64 temp tag" || echo "⚠️ ARM64 temp tag not found or already deleted"

echo "βœ… Temp tags cleaned up from Docker Hub"

# Store the version tag for the release step
echo "IMAGE_TAG=${VERSION_TAG}" >> $GITHUB_ENV

release:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
container:
image: golang:1.18.0-bullseye
image: golang:1.24
env:
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"
steps:
- name: ci/checkout-repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: ci/install-release-dependencies
run: make deps
- name: ci/publish-release
run: make release
needs: [push-docker]
needs: [create-manifest]
Loading
Loading