-
Notifications
You must be signed in to change notification settings - Fork 2
109 lines (95 loc) · 3.19 KB
/
docker-bp.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
# This is a basic workflow to help you get started with Actions
name: Docker build & Push
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_call:
inputs:
PROJECT_NAME:
required: true
type: string
PR_MESSAGE:
required: false
type: boolean
default: false
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "deploy"
buildpush:
# The type of runner that the job will run on
runs-on: [ ubuntu-latest]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
signalwire/${{ inputs.PROJECT_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and export to Docker
uses: docker/build-push-action@v3
with:
load: true
tags: ${{ steps.meta.outputs.tags }}
- name: Test
if: github.event_name == 'pull_request'
id: test
run: |
docker run -d --rm --name test ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
sleep 20
docker logs test > logs.txt
EXECUTIONLOG=$(cat logs.txt)
EXECUTIONLOG="${EXECUTIONLOG//'%'/'%25'}"
EXECUTIONLOG="${EXECUTIONLOG//$'\n'/'%0A'}"
EXECUTIONLOG="${EXECUTIONLOG//$'\r'/'%0D'}"
echo "::set-output name=container-logs::$EXECUTIONLOG"
- name: Update Pull Request
uses: actions/github-script@v6
if: github.event_name == 'pull_request' && ${{ inputs.PR_MESSAGE }} == true
env:
LOGPRINT: "${{ steps.test.outputs.container-logs }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Container logs are listed bellow 📝\`
<details><summary>Show Logs</summary>
\`\`\`\n
${process.env.LOGPRINT}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Build and push
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.meta.outputs.tags }}