-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (66 loc) · 2.58 KB
/
release.yaml
File metadata and controls
74 lines (66 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Docker Image CI
on:
release:
types: [created]
workflow_dispatch:
inputs:
component:
description: 'Component name (e.g., releaser, mongodump)'
required: true
version:
description: 'Version number (e.g., 0.1.0)'
required: true
pull_request:
branches: [ main ]
paths:
- '**/Dockerfile'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Extract component and semantic version
id: extract_info
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
TAG=${GITHUB_REF#refs/tags/}
COMPONENT=$(echo $TAG | cut -d'-' -f1)
SEMANTIC=$(echo $TAG | cut -d'-' -f2-)
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
COMPONENT="${{ github.event.inputs.component }}"
SEMANTIC="${{ github.event.inputs.version }}"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
COMPONENT=$(echo "${{ github.event.pull_request.title }}" | grep -oP '^\w+' || echo "test")
SEMANTIC="pr-${{ github.event.pull_request.number }}"
fi
echo "::set-output name=COMPONENT::$COMPONENT"
echo "::set-output name=SEMANTIC::$SEMANTIC"
echo "::set-output name=WORKFLOW_NAME::$COMPONENT Docker Image CI"
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Check if Dockerfile exists
id: dockerfile_check
run: |
if [ -f "${{ steps.extract_info.outputs.COMPONENT }}/Dockerfile" ]; then
echo "::set-output name=EXISTS::true"
else
echo "::set-output name=EXISTS::false"
echo "No Dockerfile found for component ${{ steps.extract_info.outputs.COMPONENT }}"
exit 1
fi
- name: Build and push Docker image
if: steps.dockerfile_check.outputs.EXISTS == 'true'
uses: docker/build-push-action@v2
with:
context: ./${{ steps.extract_info.outputs.COMPONENT }}
file: ./${{ steps.extract_info.outputs.COMPONENT }}/Dockerfile
push: ${{ github.event_name == 'release' }}
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:${{ steps.extract_info.outputs.SEMANTIC }}
${{ secrets.DOCKER_USERNAME }}/${{ steps.extract_info.outputs.COMPONENT }}:latest
- name: Echo Workflow Name
run: |
echo "Current workflow name: ${{ steps.extract_info.outputs.WORKFLOW_NAME }}"