Files
service-http/.github/workflows/cicd.yml
lwnmengjing a13fdc1fc7
Some checks failed
CI / build (push) Failing after 55s
Add Node.js setup step to CI workflow
2025-11-13 17:22:11 +08:00

130 lines
4.1 KiB
YAML

name: CI
on:
push:
paths-ignore:
- 'docs/**'
# - '.github/**'
- '.gitignore'
branches:
- main
tags:
- 'v*.*.*'
pull_request:
branches:
- main
env:
# Use docker.io for Docker Hub if empty
REGISTRY: git.mss-boot-io.top
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v6
with:
node-version: 24
- name: Checkout
uses: actions/checkout@v4
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: 1.25
- name: Install dependencies
run: make deps
# - name: Unit Test
# run: make test
# - name: Convert coverage report to table
# run: go tool cover -func=coverage.out | tail -n +2 | awk '{print "|",$1,"|",$3,"|"}' > coverage_table.md
# - name: Comment on PR with coverage table
# if: github.event_name == 'pull_request'
# working-directory: cmd/tools/pr
# run: go mod tidy && go run main.go
# continue-on-error: true
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# REPO_NAME: ${{ github.repository }}
# PR_NUMBER: ${{ github.event.number }}
# COVERAGE_FILE: ../../../coverage_table.md
- name: Build
run: make build
- name: Vendor
run: go mod vendor
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Prepare registry credentials
if: github.event_name != 'pull_request'
# Prepare environment variables for the login step. This avoids complex
# expressions inside the action input and makes the intent explicit.
run: |
echo "REGISTRY_USER=${{ secrets.DOCKER_USERNAME || github.actor }}" >> $GITHUB_ENV
echo "REGISTRY_PASS=${{ secrets.DOCKER_PASSWORD || secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASS }}
- name: Check docker availability
if: github.event_name != 'pull_request'
id: docker-check
# Make a clear, fast check whether 'docker' CLI + daemon are usable on the runner.
run: |
if command -v docker >/dev/null 2>&1; then
# Try a quick docker info to ensure the daemon is reachable.
if docker info >/dev/null 2>&1; then
echo "present=true" >> $GITHUB_OUTPUT
else
echo "present=false" >> $GITHUB_OUTPUT
echo "docker-cli-present=true-but-daemon-unavailable" >&2
fi
else
echo "present=false" >> $GITHUB_OUTPUT
echo "docker-cli-missing" >&2
fi
- name: Set up QEMU
if: github.event_name != 'pull_request'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: github.event_name != 'pull_request'
uses: docker/setup-buildx-action@v3
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v5
with:
images: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}'
flavor: |
latest=auto
tags: |
type=schedule
type=ref,event=tag
type=sha,prefix=,format=long,enable=true,priority=100
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}