-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (116 loc) · 4.25 KB
/
docker-hub.yml
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Docker Image Push
on:
push:
branches: [main]
merge_group:
pull_request:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Automatically cancel in-progress actions on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
cancel-in-progress: true
env:
REGISTRY: docker.io
IMAGE_NAME: trueberryless/trueberryless
NODE_VERSION: 18
jobs:
docker-push-image:
if: contains(github.event.head_commit.message, 'version') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if file exists
run: |
if [ -f .github/artifacts/version.json ]; then
echo "File exists"
echo "FILE_EXISTS=true" >> $GITHUB_ENV
else
echo "File does not exist"
echo "FILE_EXISTS=false" >> $GITHUB_ENV
fi
- name: read_json
if: ${{ env.FILE_EXISTS == 'true' }}
id: version
uses: zoexx/github-action-json-file-properties@release
with:
file_path: ".github/artifacts/version.json"
- name: save environment variables
if: ${{ env.FILE_EXISTS == 'true' }}
run: |
echo "MAJOR=${{steps.version.outputs.major}}" >> $GITHUB_ENV
echo "MINOR=${{steps.version.outputs.minor}}" >> $GITHUB_ENV
echo "PATCH=${{steps.version.outputs.patch}}" >> $GITHUB_ENV
- name: create environment variables
if: ${{ env.FILE_EXISTS == 'false' }}
run: |
echo "MAJOR=0" >> $GITHUB_ENV
echo "MINOR=0" >> $GITHUB_ENV
echo "PATCH=0" >> $GITHUB_ENV
- name: echo environment variables
run: |
echo ${{ env.MINOR }}
echo ${{ env.MINOR }}
echo ${{ env.MINOR }}
- name: Major version
if: contains(github.event.head_commit.message, 'major')
run: |
echo "New major version"
echo "MAJOR=$((${{ env.MAJOR }}+1))" >> $GITHUB_ENV
echo "MINOR=0" >> $GITHUB_ENV
echo "PATCH=0" >> $GITHUB_ENV
- name: Minor version
if: contains(github.event.head_commit.message, 'minor')
run: |
echo "New minor version"
echo "MINOR=$((${{ env.MINOR }}+1))" >> $GITHUB_ENV
echo "PATCH=0" >> $GITHUB_ENV
- name: Patch version
if: contains(github.event.head_commit.message, 'patch') || github.event_name == 'workflow_dispatch'
run: |
echo "New patch version"
echo "PATCH=$((${{ env.PATCH }}+1))" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ env.MAJOR}}.${{ env.MINOR}}.${{ env.PATCH}}
${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create folder if necessary
if: ${{ env.FILE_EXISTS == 'false' }}
run: mkdir -p .github/artifacts
- name: write_json
id: create-json
uses: jsdaniell/[email protected]
with:
name: "version.json"
json: '{ "major": ${{ env.MAJOR }}, "minor": ${{ env.MINOR }}, "patch": ${{ env.PATCH }} }'
dir: '.github/artifacts/'
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: update version.json (automated)