-
Notifications
You must be signed in to change notification settings - Fork 2
121 lines (106 loc) · 4.11 KB
/
cicd.yaml
File metadata and controls
121 lines (106 loc) · 4.11 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
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
name: CI/CD
on:
push:
branches:
- main
pull_request:
concurrency: cicd
jobs:
build-and-test-snapshot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Build
run: make
- name: Install gh dispatch
run: make install
- name: Acceptance test
if: github.actor != 'dependabot[bot]'
run: make acc-test
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ensure-unpublished-version:
runs-on: ubuntu-latest
needs: build-and-test-snapshot
permissions:
actions: write
outputs:
commit-author: ${{ steps.commit-author.outputs.commit-author }}
commit-message: ${{ steps.commit-message.outputs.commit-message }}
skipped: ${{ steps.ensure-unpublished-version.outputs.skipped }}
exists: ${{ steps.ensure-unpublished-version.outputs.exists }}
steps:
- uses: actions/checkout@v6
- name: Get commit message (pull_request)
if: github.event_name == 'pull_request'
run: |
pr_num="${{ github.event.pull_request.number }}"
git fetch origin refs/pull/${pr_num}/head:refs/remotes/origin/pull/${pr_num}/head
echo "COMMIT_MESSAGE="$(git log -1 --pretty=format:"%B" origin/pull/${pr_num}/head)"" >> $GITHUB_ENV
echo "PR_NUM="${pr_num}"" >> $GITHUB_ENV
- name: Get commit message (push, etc.)
if: ${{ github.event_name != 'pull_request' }}
run: echo "COMMIT_MESSAGE="$(git log -1 --pretty=%B)"" >> $GITHUB_ENV
- name: Get commit author (pull request)
if: ${{ github.event_name == 'pull_request' }}
run: echo "COMMIT_AUTHOR="$(git log -1 --pretty=format:"%an" origin/pull/${PR_NUM}/head)"" >> $GITHUB_ENV
- name: Get commit author (push, etc.)
if: ${{ github.event_name != 'pull_request' }}
run: echo "COMMIT_AUTHOR="$(git log -1 --pretty=%an)"" >> $GITHUB_ENV
- name: Get commit details
id: commit-details
run: |
echo "commit-author="${COMMIT_AUTHOR}"" >> $GITHUB_OUTPUT
echo "commit-message="${COMMIT_MESSAGE}"" >> $GITHUB_OUTPUT
- name: Show commit details
run: |
echo "author: ${{ steps.commit-details.outputs.commit-author }}"
echo "commit message: ${{ steps.commit-details.outputs.commit-message }}"
- name: Get version
run: echo "VERSION=$(make version)" >> $GITHUB_ENV
- uses: mdb/ensure-unpublished-release-action@main
id: ensure-unpublished-version
with:
tag: ${{ env.VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
skip-authors: 'dependabot[bot]'
author: ${{ steps.commit-details.outputs.commit-author }}
skip-commit-message-pattern: '[skip release]'
commit-message: ${{ steps.commit-details.outputs.commit-message }}
- name: Show ensure-unpublished-version outputs
if: ${{ always() }}
run: |
echo "skipped: ${{ steps.ensure-unpublished-version.outputs.skipped }}"
echo "exists: ${{ steps.ensure-unpublished-version.outputs.exists }}"
- name: Trigger dependabot PR merge workflow
if: (github.event_name == 'pull_request') && (steps.commit-details.outputs.commit-author == 'dependabot[bot]')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh workflow run \
merge-pr.yaml \
--field pr-number="$PR_NUM"
build-and-publish-release:
if: github.ref == 'refs/heads/main' && needs.ensure-unpublished-version.outputs.skipped != 'true'
runs-on: ubuntu-latest
needs: ensure-unpublished-version
environment:
name: release
steps:
- uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Create release tag
run: make tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build & Release
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}