-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (73 loc) · 2.53 KB
/
release.yml
File metadata and controls
80 lines (73 loc) · 2.53 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
75
76
77
78
79
80
name: Release Docker Image
on:
workflow_dispatch:
workflow_run:
workflows: [Run Integration Tests]
branches:
- main
types:
- completed
jobs:
run_checks:
name: Run checks
runs-on: ubuntu-latest
outputs:
pass: ${{ steps.run_checks_step.outputs.result }}
steps:
- name: Run checks
id: run_checks_step
uses: actions/github-script@v6
with:
script: |
const isWorkflowRunEvent = ${{ github.event_name == 'workflow_run' }}
const isWorkflowDispatchEvent = ${{ github.event_name == 'workflow_dispatch' }}
if (isWorkflowRunEvent) {
const isWorkflowRunSuccess = ${{ github.event.workflow_run.conclusion == 'success' }}
const commitContainsRelease = ${{ contains(github.event.workflow_run.head_commit.message, '[release]') }}
if (isWorkflowRunSuccess && commitContainsRelease) {
console.log("Running workfloy triggered by workflow_run...")
return true
}
} else if (isWorkflowDispatchEvent) {
console.log("Running workfloy triggered by workflow_dispatch...")
return true
}
console.log("None of conditions met. Cancel")
return false
push_to_registry:
name: Build & Push image to DockerHub
runs-on: ubuntu-latest
needs: run_checks
if: ${{ needs.run_checks.outputs.pass == 'true' }}
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Bump version and push tag
id: github_tag_action
uses: anothrNick/github-tag-action@1.67.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
- name: Make release tags
id: make_release_tags
run: |
raw_tag=${{ steps.github_tag_action.outputs.new_tag }}
tag=${raw_tag:1}
image_name=${{ secrets.DOCKER_USERNAME }}/${PWD##*/}
tags=$image_name:latest,$image_name:$tag
echo "tags=$tags" >> "$GITHUB_OUTPUT"
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.make_release_tags.outputs.tags }}