-
Notifications
You must be signed in to change notification settings - Fork 14
91 lines (79 loc) · 2.7 KB
/
build_config_server.yaml
File metadata and controls
91 lines (79 loc) · 2.7 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
81
82
83
84
85
86
87
88
89
90
91
name: Build Config Server
on:
pull_request:
branches:
- main
paths:
- '.github/workflows/build_config_server.yaml'
- 'config-server/**'
- 'build.ps1'
push:
branches:
- main
paths:
- '.github/workflows/build_config_server.yaml'
- 'config-server/**'
- 'build.ps1'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: 'write'
env:
IMAGE_NAME: config-server
REGISTRY: ${{ vars.DOCKER_REGISTRY }}
jobs:
build-push:
name: Build and push image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Image
run: ./build.ps1 -Name '${{ env.IMAGE_NAME }}' -Registry '${{ env.REGISTRY }}' -Tag '${{ env.TAG }}'
shell: pwsh
env:
TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || '' }}
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ${{ vars.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push image
run: docker push --all-tags ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Post or update PR comment with image run instructions
uses: actions/github-script@v7
if: ${{ github.event_name == 'pull_request' }}
with:
script: |
const marker = '<!-- IMAGE_INSTRUCTIONS_CONFIG_SERVER -->';
const body = `${marker}
To run the Spring Cloud Config Server image built for this pull request:
\`\`\`bash
docker run --rm -d --pull=always -p 8888:8888 --name config-pr steeltoe.azurecr.io/config-server:pr-${{ github.event.number }}
\`\`\``;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
const existingComment = comments.find(comment =>
comment.user.login === 'github-actions[bot]' && comment.body.startsWith(marker)
);
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}