refactor: split ci.yml into branch-specific orchestrators, extract version check
- ci.yml: pure dispatch (Feature → ci-feature, Main → ci-main), 18 lines - ci-feature.yml (new): load-config → quality-gate - ci-main.yml (new): load-config → check-version → quality-gate → docker-build-push - check-version.yml (new): provider workflow for artifact existence check and version calculation - docker-build-push.yml (renamed from build_publish-artifact.yml): - removed check job, quality-gate block, gatekeeper logic, build-context artifact - version passed as input, simplified needs chain (build → push → tag-commit) - fixed consumer→provider checkout pattern (.ci/scripts/)
This commit is contained in:
@@ -1,330 +0,0 @@
|
||||
name: Build & Publish Artifact
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
env_json:
|
||||
required: true
|
||||
type: string
|
||||
bats-image:
|
||||
required: true
|
||||
type: string
|
||||
cucumber-node-image:
|
||||
required: true
|
||||
type: string
|
||||
secrets:
|
||||
GITEA_TOKEN:
|
||||
required: true
|
||||
GIT_PAGES_PUBLISH_TOKEN:
|
||||
required: true
|
||||
DOCKER_USERNAME:
|
||||
required: false
|
||||
DOCKER_PASSWORD:
|
||||
required: true
|
||||
|
||||
env:
|
||||
GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }}
|
||||
GIT_PAGES_URL: ${{ fromJson(inputs.env_json).GIT_PAGES_URL }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GIT_PAGES_PUBLISH_TOKEN: ${{ secrets.GIT_PAGES_PUBLISH_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
DOCKER_REGISTRY: ${{ fromJson(inputs.env_json).DOCKER_REGISTRY || '' }}
|
||||
DOCKER_IMAGE_NAME: ${{ fromJson(inputs.env_json).DOCKER_IMAGE_NAME || '' }}
|
||||
DOCKER_UI_URL: ${{ fromJson(inputs.env_json).DOCKER_UI_URL || '' }}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
artifact_exists: ${{ steps.set-outputs.outputs.artifact_exists }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Check existing artifact | begin ====="
|
||||
bash scripts/report-status.sh pending "Checking version..." ci-check
|
||||
|
||||
- name: Check existing artifact and calculate version
|
||||
run: |
|
||||
RAW_VERSION=$(jq -r '.version' package.json)
|
||||
BASE_VERSION=$(echo "$RAW_VERSION" | cut -d'.' -f1-2)
|
||||
echo "gitea-ci-library - Tunnistettu Major.Minor versio: $BASE_VERSION"
|
||||
|
||||
TAGS_JSON=$(curl -s -f -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
||||
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/tags")
|
||||
|
||||
TAG=$(echo "$TAGS_JSON" | jq -r 'if type == "array" then .[] | select(.commit.sha == "${{ github.sha }}") | .name else empty end' | head -1)
|
||||
|
||||
mkdir -p /tmp/build-ctx
|
||||
|
||||
if [ -n "$TAG" ]; then
|
||||
echo "ARTIFACT_EXISTS=true" > /tmp/build-ctx/build.env
|
||||
echo "NEXT_VERSION=$TAG" >> /tmp/build-ctx/build.env
|
||||
echo "gitea-ci-library - Artefakti löytyi jo tagilla: $TAG."
|
||||
else
|
||||
echo "ARTIFACT_EXISTS=false" > /tmp/build-ctx/build.env
|
||||
|
||||
HIGHEST_PATCH=$(echo "$TAGS_JSON" | jq -r --arg bv "$BASE_VERSION." '
|
||||
if type == "array" then .[] | .name | select(startswith($bv)) | sub($bv; "") | tonumber else empty end' | sort -rn | head -1)
|
||||
|
||||
if [ -z "$HIGHEST_PATCH" ]; then NEXT_PATCH=0; else NEXT_PATCH=$((HIGHEST_PATCH + 1)); fi
|
||||
FULL_VERSION="${BASE_VERSION}.${NEXT_PATCH}"
|
||||
|
||||
echo "NEXT_VERSION=$FULL_VERSION" >> /tmp/build-ctx/build.env
|
||||
echo "gitea-ci-library - Uusi vapaa versio: $FULL_VERSION"
|
||||
fi
|
||||
|
||||
- name: Set job outputs
|
||||
id: set-outputs
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
echo "artifact_exists=$ARTIFACT_EXISTS" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Upload build env artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: build-context
|
||||
path: /tmp/build-ctx/build.env
|
||||
retention-days: 1
|
||||
|
||||
- name: Set Gitea status to SUCCESS
|
||||
if: success()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
if [ "${ARTIFACT_EXISTS}" = "true" ]; then
|
||||
bash scripts/report-status.sh success "Skip build: version $NEXT_VERSION exists" ci-check
|
||||
else
|
||||
bash scripts/report-status.sh success "Build version $NEXT_VERSION required" ci-check
|
||||
fi
|
||||
|
||||
- name: Set Gitea status to FAILURE
|
||||
if: failure()
|
||||
run: bash scripts/report-status.sh failure "Check version FAILED" ci-check
|
||||
|
||||
# quality-gate:
|
||||
# needs: [check]
|
||||
# uses: niko/gitea-ci-library/.gitea/workflows/quality-gate.yml@main
|
||||
# secrets: inherit
|
||||
# with:
|
||||
# env_json: ${{ inputs.env_json }}
|
||||
# bats-image: ${{ inputs.bats-image }}
|
||||
# cucumber-node-image: ${{ inputs.cucumber-node-image }}
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
# needs: [check, quality-gate]
|
||||
needs: [check]
|
||||
# Skipataan koko build jos artefakti löytyy jo
|
||||
if: needs.check.outputs.artifact_exists != 'true'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download build env
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: build-context
|
||||
path: /tmp/build-ctx
|
||||
|
||||
- name: Check if build needed
|
||||
id: gatekeeper
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
if [ "${ARTIFACT_EXISTS}" = "true" ]; then
|
||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
if: steps.gatekeeper.outputs.skip == 'false'
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Docker Build | begin ====="
|
||||
bash scripts/report-status.sh pending "Building Docker image..." ci-docker-build
|
||||
|
||||
- name: Build container
|
||||
if: steps.gatekeeper.outputs.skip == 'false'
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
docker build \
|
||||
--label "git.commit=${{ github.sha }}" \
|
||||
--label "git.commitBy=${{ github.actor }}" \
|
||||
--label "build.date=${NOW}" \
|
||||
-t "${DOCKER_IMAGE_NAME}:${NEXT_VERSION}" .
|
||||
|
||||
- name: Report status SUCCESS
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && success()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
bash scripts/report-status.sh success "Docker build $NEXT_VERSION OK" ci-docker-build
|
||||
|
||||
- name: Report status FAILURE
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && failure()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
bash scripts/report-status.sh failure "Docker build $NEXT_VERSION FAILED" ci-docker-build
|
||||
|
||||
- name: Save Docker image
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && success()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
mkdir -p /tmp/image
|
||||
docker save "${DOCKER_IMAGE_NAME}:${NEXT_VERSION}" -o /tmp/image/artifact.tar
|
||||
|
||||
- name: Upload Docker image artifact
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && success()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: docker-image
|
||||
path: /tmp/image/artifact.tar
|
||||
retention-days: 1
|
||||
|
||||
push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [check, build]
|
||||
if: needs.check.outputs.artifact_exists != 'true'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download build env
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: build-context
|
||||
path: /tmp/build-ctx
|
||||
|
||||
- name: Verify Build Status
|
||||
id: gatekeeper
|
||||
run: |
|
||||
BUILD_RESULT="${{ needs.build.result }}"
|
||||
source /tmp/build-ctx/build.env
|
||||
if [ "$BUILD_RESULT" != "success" ]; then
|
||||
echo "gitea-ci-library - Edellinen vaihe epäonnistui. Keskeytetään." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "${ARTIFACT_EXISTS}" = "true" ]; then
|
||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Load saved Docker image
|
||||
if: steps.gatekeeper.outputs.skip == 'false'
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: docker-image
|
||||
path: /tmp/image
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
if: steps.gatekeeper.outputs.skip == 'false'
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Docker Push | begin ====="
|
||||
bash scripts/report-status.sh pending "Pushing to registry..." ci-docker-push
|
||||
|
||||
- name: Push to Docker Registry
|
||||
if: steps.gatekeeper.outputs.skip == 'false'
|
||||
env:
|
||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME || github.actor }}
|
||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
docker load -i /tmp/image/artifact.tar
|
||||
|
||||
REGISTRY="${DOCKER_REGISTRY:?DOCKER_REGISTRY not set in env.conf}"
|
||||
IMAGE="${DOCKER_IMAGE_NAME:?DOCKER_IMAGE_NAME not set in env.conf}"
|
||||
REGISTRY_HOST="${REGISTRY%%/*}"
|
||||
|
||||
FULL_IMAGE="${REGISTRY}/${IMAGE}:${NEXT_VERSION}"
|
||||
echo "Pushing ${FULL_IMAGE} ..."
|
||||
|
||||
docker tag "${DOCKER_IMAGE_NAME}:${NEXT_VERSION}" "$FULL_IMAGE"
|
||||
echo "$DOCKER_PASSWORD" | docker login "$REGISTRY_HOST" -u "$DOCKER_USERNAME" --password-stdin
|
||||
docker push "$FULL_IMAGE"
|
||||
docker logout "$REGISTRY_HOST"
|
||||
|
||||
- name: Report status SUCCESS
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && success()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
CONTAINER_URL=""
|
||||
if [ -n "${DOCKER_UI_URL:-}" ] && [ -n "${NEXT_VERSION:-}" ]; then
|
||||
CONTAINER_URL="${DOCKER_UI_URL}/${NEXT_VERSION}"
|
||||
fi
|
||||
bash scripts/report-status.sh success "Docker push $NEXT_VERSION OK" ci-docker-push "" "$CONTAINER_URL"
|
||||
|
||||
- name: Report status FAILURE
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && failure()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
bash scripts/report-status.sh failure "Docker push $NEXT_VERSION FAILED" ci-docker-push
|
||||
|
||||
tag-commit:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [check, push]
|
||||
if: needs.check.outputs.artifact_exists != 'true'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Download build env
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: build-context
|
||||
path: /tmp/build-ctx
|
||||
|
||||
- name: Verify Push Status
|
||||
id: gatekeeper
|
||||
run: |
|
||||
PUSH_RESULT="${{ needs.push.result }}"
|
||||
source /tmp/build-ctx/build.env
|
||||
if [ "$PUSH_RESULT" != "success" ]; then
|
||||
echo "gitea-ci-library - Push vaihe epäonnistui. Keskeytetään." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "${ARTIFACT_EXISTS}" = "true" ]; then
|
||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
if: steps.gatekeeper.outputs.skip == 'false'
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Create Tag | begin ====="
|
||||
bash scripts/report-status.sh pending "Creating tag..." ci-docker-tag
|
||||
|
||||
- name: Create git tag
|
||||
if: steps.gatekeeper.outputs.skip == 'false'
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
REPO: ${{ github.repository }}
|
||||
SERVER_URL: ${{ gitea.server_url }}
|
||||
RUN_NUMBER: ${{ github.run_number }}
|
||||
SHA: ${{ github.sha }}
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||
"$SERVER_URL/api/v1/repos/$REPO/tags" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\": \"$NEXT_VERSION\", \"message\": \"Build #$RUN_NUMBER\", \"target\": \"$SHA\"}")
|
||||
|
||||
if [ "$HTTP_CODE" = "201" ] || [ "$HTTP_CODE" = "409" ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Report status SUCCESS
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && success()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
bash scripts/report-status.sh success "Tag $NEXT_VERSION OK" ci-docker-tag
|
||||
|
||||
- name: Report status FAILURE
|
||||
if: steps.gatekeeper.outputs.skip == 'false' && failure()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
bash scripts/report-status.sh failure "Tag $NEXT_VERSION FAILED" ci-docker-tag
|
||||
@@ -0,0 +1,88 @@
|
||||
name: Check Existing Artifact
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
env_json:
|
||||
required: true
|
||||
type: string
|
||||
secrets:
|
||||
GITEA_TOKEN:
|
||||
required: true
|
||||
outputs:
|
||||
artifact_exists:
|
||||
value: ${{ jobs.check.outputs.artifact_exists }}
|
||||
version:
|
||||
value: ${{ jobs.check.outputs.version }}
|
||||
|
||||
env:
|
||||
GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
artifact_exists: ${{ steps.set-outputs.outputs.artifact_exists }}
|
||||
version: ${{ steps.set-outputs.outputs.version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: niko/gitea-ci-library
|
||||
path: .ci
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Check existing artifact | begin ====="
|
||||
bash .ci/scripts/report-status.sh pending "Checking version..." ci-check
|
||||
|
||||
- name: Check existing artifact and calculate version
|
||||
run: |
|
||||
RAW_VERSION=$(jq -r '.version' package.json)
|
||||
BASE_VERSION=$(echo "$RAW_VERSION" | cut -d'.' -f1-2)
|
||||
echo "gitea-ci-library - Tunnistettu Major.Minor versio: $BASE_VERSION"
|
||||
|
||||
TAGS_JSON=$(curl -s -f -H "Authorization: token $GITEA_TOKEN" \
|
||||
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/tags")
|
||||
|
||||
TAG=$(echo "$TAGS_JSON" | jq -r 'if type == "array" then .[] | select(.commit.sha == "${{ github.sha }}") | .name else empty end' | head -1)
|
||||
|
||||
mkdir -p /tmp/build-ctx
|
||||
|
||||
if [ -n "$TAG" ]; then
|
||||
echo "ARTIFACT_EXISTS=true" > /tmp/build-ctx/build.env
|
||||
echo "NEXT_VERSION=$TAG" >> /tmp/build-ctx/build.env
|
||||
echo "gitea-ci-library - Artefakti löytyi jo tagilla: $TAG."
|
||||
else
|
||||
echo "ARTIFACT_EXISTS=false" > /tmp/build-ctx/build.env
|
||||
|
||||
HIGHEST_PATCH=$(echo "$TAGS_JSON" | jq -r --arg bv "$BASE_VERSION." '
|
||||
if type == "array" then .[] | .name | select(startswith($bv)) | sub($bv; "") | tonumber else empty end' | sort -rn | head -1)
|
||||
|
||||
if [ -z "$HIGHEST_PATCH" ]; then NEXT_PATCH=0; else NEXT_PATCH=$((HIGHEST_PATCH + 1)); fi
|
||||
FULL_VERSION="${BASE_VERSION}.${NEXT_PATCH}"
|
||||
|
||||
echo "NEXT_VERSION=$FULL_VERSION" >> /tmp/build-ctx/build.env
|
||||
echo "gitea-ci-library - Uusi vapaa versio: $FULL_VERSION"
|
||||
fi
|
||||
|
||||
- name: Set job outputs
|
||||
id: set-outputs
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
echo "artifact_exists=$ARTIFACT_EXISTS" >> "$GITHUB_OUTPUT"
|
||||
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Set Gitea status to SUCCESS
|
||||
if: success()
|
||||
run: |
|
||||
source /tmp/build-ctx/build.env
|
||||
if [ "${ARTIFACT_EXISTS}" = "true" ]; then
|
||||
bash .ci/scripts/report-status.sh success "Skip build: version $NEXT_VERSION exists" ci-check
|
||||
else
|
||||
bash .ci/scripts/report-status.sh success "Build version $NEXT_VERSION required" ci-check
|
||||
fi
|
||||
|
||||
- name: Set Gitea status to FAILURE
|
||||
if: failure()
|
||||
run: bash .ci/scripts/report-status.sh failure "Check version FAILED" ci-check
|
||||
@@ -0,0 +1,20 @@
|
||||
name: CI Feature
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
name: Load gitea-env.conf to pipeline env
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main
|
||||
with:
|
||||
config_path: .gitea/workflows/gitea-env.conf
|
||||
|
||||
quality-gate:
|
||||
name: Quality Gate
|
||||
needs: [load-config]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/quality-gate.yml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
bats-image: bats/bats:latest
|
||||
cucumber-node-image: node:22
|
||||
@@ -0,0 +1,39 @@
|
||||
name: CI Main
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
name: Load gitea-env.conf to pipeline env
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main
|
||||
with:
|
||||
config_path: .gitea/workflows/gitea-env.conf
|
||||
|
||||
check-version:
|
||||
name: Check existing artifact
|
||||
needs: [load-config]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/check-version.yml@feature/docker-kuntoon
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
|
||||
quality-gate:
|
||||
name: Quality Gate
|
||||
needs: [load-config, check-version]
|
||||
if: needs.check-version.outputs.artifact_exists != 'true'
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/quality-gate.yml@main
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
bats-image: bats/bats:latest
|
||||
cucumber-node-image: node:22
|
||||
|
||||
build-push:
|
||||
name: Build & Push Docker
|
||||
needs: [load-config, check-version, quality-gate]
|
||||
if: needs.check-version.outputs.artifact_exists != 'true'
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/docker-build-push.yml@feature/docker-kuntoon
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
version: ${{ needs.check-version.outputs.version }}
|
||||
+8
-24
@@ -5,30 +5,14 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
load-config:
|
||||
name: Load gitea-env.conf to pipeline env
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/config-provider.yml@main
|
||||
with:
|
||||
config_path: .gitea/workflows/gitea-env.conf
|
||||
|
||||
# feature:
|
||||
# name: Quality Gate
|
||||
# if: github.ref != 'refs/heads/main'
|
||||
# needs: [load-config]
|
||||
# uses: niko/gitea-ci-library/.gitea/workflows/quality-gate.yml@main
|
||||
# secrets: inherit
|
||||
# with:
|
||||
# env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
# bats-image: bats/bats:latest
|
||||
# cucumber-node-image: node:22
|
||||
feature:
|
||||
name: Feature
|
||||
if: github.ref != 'refs/heads/main'
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/ci-feature.yml@feature/docker-kuntoon
|
||||
secrets: inherit
|
||||
|
||||
main:
|
||||
name: Build & Push Artifact
|
||||
# if: github.ref == 'refs/heads/main' # FIXME: väliaikainen — ajetaan tässä haarassa
|
||||
needs: [load-config]
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/build_publish-artifact.yml@feature/docker-kuntoon
|
||||
name: Main
|
||||
if: github.ref == 'refs/heads/main'
|
||||
uses: niko/gitea-ci-library/.gitea/workflows/ci-main.yml@feature/docker-kuntoon
|
||||
secrets: inherit
|
||||
with:
|
||||
env_json: ${{ needs.load-config.outputs.env_json }}
|
||||
bats-image: bats/bats:latest
|
||||
cucumber-node-image: node:22
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
name: Docker Build & Push
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
env_json:
|
||||
required: true
|
||||
type: string
|
||||
version:
|
||||
required: true
|
||||
type: string
|
||||
secrets:
|
||||
GITEA_TOKEN:
|
||||
required: true
|
||||
DOCKER_USERNAME:
|
||||
required: false
|
||||
DOCKER_PASSWORD:
|
||||
required: true
|
||||
|
||||
env:
|
||||
GITEA_API_URL: ${{ fromJson(inputs.env_json).GITEA_API_URL }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
DOCKER_REGISTRY: ${{ fromJson(inputs.env_json).DOCKER_REGISTRY || '' }}
|
||||
DOCKER_IMAGE_NAME: ${{ fromJson(inputs.env_json).DOCKER_IMAGE_NAME || '' }}
|
||||
DOCKER_UI_URL: ${{ fromJson(inputs.env_json).DOCKER_UI_URL || '' }}
|
||||
VERSION: ${{ inputs.version }}
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: niko/gitea-ci-library
|
||||
path: .ci
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Docker Build | begin ====="
|
||||
bash .ci/scripts/report-status.sh pending "Building Docker image..." ci-docker-build
|
||||
|
||||
- name: Build container
|
||||
run: |
|
||||
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
docker build \
|
||||
--label "git.commit=${{ github.sha }}" \
|
||||
--label "git.commitBy=${{ github.actor }}" \
|
||||
--label "build.date=${NOW}" \
|
||||
-t "${DOCKER_IMAGE_NAME}:${VERSION}" .
|
||||
|
||||
- name: Report status SUCCESS
|
||||
if: success()
|
||||
run: bash .ci/scripts/report-status.sh success "Docker build ${VERSION} OK" ci-docker-build
|
||||
|
||||
- name: Report status FAILURE
|
||||
if: failure()
|
||||
run: bash .ci/scripts/report-status.sh failure "Docker build ${VERSION} FAILED" ci-docker-build
|
||||
|
||||
- name: Save Docker image
|
||||
if: success()
|
||||
run: |
|
||||
mkdir -p /tmp/image
|
||||
docker save "${DOCKER_IMAGE_NAME}:${VERSION}" -o /tmp/image/artifact.tar
|
||||
|
||||
- name: Upload Docker image artifact
|
||||
if: success()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: docker-image
|
||||
path: /tmp/image/artifact.tar
|
||||
retention-days: 1
|
||||
|
||||
push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: niko/gitea-ci-library
|
||||
path: .ci
|
||||
|
||||
- name: Load saved Docker image
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: docker-image
|
||||
path: /tmp/image
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Docker Push | begin ====="
|
||||
bash .ci/scripts/report-status.sh pending "Pushing to registry..." ci-docker-push
|
||||
|
||||
- name: Push to Docker Registry
|
||||
env:
|
||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME || github.actor }}
|
||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||
run: |
|
||||
docker load -i /tmp/image/artifact.tar
|
||||
|
||||
REGISTRY="${DOCKER_REGISTRY:?DOCKER_REGISTRY not set in env.conf}"
|
||||
IMAGE="${DOCKER_IMAGE_NAME:?DOCKER_IMAGE_NAME not set in env.conf}"
|
||||
REGISTRY_HOST="${REGISTRY%%/*}"
|
||||
|
||||
FULL_IMAGE="${REGISTRY}/${IMAGE}:${VERSION}"
|
||||
echo "Pushing ${FULL_IMAGE} ..."
|
||||
|
||||
docker tag "${DOCKER_IMAGE_NAME}:${VERSION}" "$FULL_IMAGE"
|
||||
echo "$DOCKER_PASSWORD" | docker login "$REGISTRY_HOST" -u "$DOCKER_USERNAME" --password-stdin
|
||||
docker push "$FULL_IMAGE"
|
||||
docker logout "$REGISTRY_HOST"
|
||||
|
||||
- name: Report status SUCCESS
|
||||
if: success()
|
||||
run: |
|
||||
CONTAINER_URL=""
|
||||
if [ -n "${DOCKER_UI_URL:-}" ] && [ -n "${VERSION:-}" ]; then
|
||||
CONTAINER_URL="${DOCKER_UI_URL}/${VERSION}"
|
||||
fi
|
||||
bash .ci/scripts/report-status.sh success "Docker push ${VERSION} OK" ci-docker-push "" "$CONTAINER_URL"
|
||||
|
||||
- name: Report status FAILURE
|
||||
if: failure()
|
||||
run: bash .ci/scripts/report-status.sh failure "Docker push ${VERSION} FAILED" ci-docker-push
|
||||
|
||||
tag-commit:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [push]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: niko/gitea-ci-library
|
||||
path: .ci
|
||||
|
||||
- name: Set Gitea status to PENDING
|
||||
run: |
|
||||
echo "===== gitea-ci-library - Create Tag | begin ====="
|
||||
bash .ci/scripts/report-status.sh pending "Creating tag..." ci-docker-tag
|
||||
|
||||
- name: Create git tag
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
SERVER_URL: ${{ gitea.server_url }}
|
||||
RUN_NUMBER: ${{ github.run_number }}
|
||||
SHA: ${{ github.sha }}
|
||||
run: |
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||
"$SERVER_URL/api/v1/repos/${{ github.repository }}/tags" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\": \"${VERSION}\", \"message\": \"Build #$RUN_NUMBER\", \"target\": \"$SHA\"}")
|
||||
|
||||
if [ "$HTTP_CODE" = "201" ] || [ "$HTTP_CODE" = "409" ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Report status SUCCESS
|
||||
if: success()
|
||||
run: bash .ci/scripts/report-status.sh success "Tag ${VERSION} OK" ci-docker-tag
|
||||
|
||||
- name: Report status FAILURE
|
||||
if: failure()
|
||||
run: bash .ci/scripts/report-status.sh failure "Tag ${VERSION} FAILED" ci-docker-tag
|
||||
Reference in New Issue
Block a user