Skip to content

Commit

Permalink
chore: updated pipelines (#60)
Browse files Browse the repository at this point in the history
rewrite pipelines with pr pipeline, branch pipeline and release pipeline
  • Loading branch information
chideat authored Aug 28, 2024
1 parent 52e4ddd commit 8e1f99d
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 77 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/branch-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: release

on:
push:
branches:
- main
- release-*

jobs:
test:
name: Test with Coverage
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Check out code
uses: actions/checkout@v4

- name: Install dependencies
run: |
go mod download
- name: Run Unit tests
run: |
make test
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest

- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: goveralls -coverprofile=coverage.txt -service=github

build:
name: Build and push Docker image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Generate tag
id: get_tag
run: |
if [ "${GITHUB_REF##*/}" = "main" ]; then
TAG_NAME="latest"
else
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
VERSION="${BRANCH_NAME#release-}"
LARGEST_TAG=$(git tag --merged $BRANCH_NAME --sort=-v:refname | grep $VERSION | head -n 1)
TAG_NAME="${LARGEST_TAG}-${GITHUB_SHA::7}"
fi
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Docker Setup Buildx
id: buildx
uses: docker/setup-buildx-action@v3.0.0

- name: GitHub Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
file: ./Dockerfile
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/redis-operator:${{ env.TAG_NAME }}
platforms: linux/amd64,linux/arm64
27 changes: 0 additions & 27 deletions .github/workflows/dev.yaml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/pr-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: dev

on: [pull_request]

jobs:
test:
name: Test with Coverage
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.22'

- name: Check out code
uses: actions/checkout@v4.1.7

- name: Install dependencies
run: |
go mod download
- name: Run Unit tests
run: |
make test
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest

- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: goveralls -coverprofile=coverage.txt -service=github

build:
name: Build and push Docker image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4.1.7

- name: Read version from file
id: get_version
run: |
ls -la
echo "VERSION=$(cat version)" >> $GITHUB_ENV
- name: Get branch name
id: get_branch
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
BRANCH_NAME=${{ github.head_ref }}
else
BRANCH_NAME=${GITHUB_REF#refs/heads/}
fi
# Replace special characters with hyphens, remove trailing hyphens, and convert to lowercase
SANITIZED_BRANCH_NAME=$(echo "$BRANCH_NAME" | tr -cs '[:alnum:]' '-' | sed 's/-*$//' | tr '[:upper:]' '[:lower:]')
echo "BRANCH_NAME=$SANITIZED_BRANCH_NAME" >> $GITHUB_ENV
- name: Get short commit SHA
id: get_commit
run: echo "COMMIT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV

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

- name: Docker Setup Buildx
id: buildx
uses: docker/setup-buildx-action@v3.0.0

- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
file: ./Dockerfile
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/redis-operator:${{ env.VERSION }}-${{ env.BRANCH_NAME }}-${{ env.COMMIT_SHA }}
platforms: linux/amd64,linux/arm64
50 changes: 50 additions & 0 deletions .github/workflows/release-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: release

on:
push:
tags:
- '*'

jobs:
build:
name: Build and push Docker image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Get the current tag
run: |
TAG=$(git describe --tags --abbrev=0)
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Docker Setup Buildx
id: buildx
uses: docker/setup-buildx-action@v3.0.0

- name: Docker Login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: GitHub Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
file: ./Dockerfile
context: .
push: true
tags: |
${{ secret.DOCKER_USERNAME }}/redis-operator:${{ env.TAG }}
ghcr.io/alauda/redis-operator:${{ env.TAG }}
platforms: linux/amd64,linux/arm64
50 changes: 0 additions & 50 deletions .github/workflows/release.yaml

This file was deleted.

0 comments on commit 8e1f99d

Please sign in to comment.