-
Notifications
You must be signed in to change notification settings - Fork 18
199 lines (182 loc) · 7 KB
/
push.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation
# Copyright 2024 Kyunghee University
name: GitHub release and Docker images
on:
push:
branches:
- master
tags:
- v*
jobs:
push-images:
runs-on: ubuntu-latest
if: github.repository_owner == 'onosproject'
env:
REGISTRY: docker.io
DOCKER_REPOSITORY: onosproject/
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- run: echo GIT_SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
- uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image with tag latest
env:
DOCKER_TAG: latest
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
git clone https://github.com/onosproject/build-tools.git build/build-tools
make images
docker push ${{ env.DOCKER_REPOSITORY }}onos-kpimon:${{ env.DOCKER_TAG }}
- name: Build and push Docker image with tag version
if: steps.version-change.outputs.changed == 'true'
env:
DOCKER_TAG: v${{ needs.tag-github.outputs.version }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
git clone https://github.com/onosproject/build-tools.git build/build-tools
make images
docker push ${{ env.DOCKER_REPOSITORY }}onos-kpimon:${{ env.DOCKER_TAG }}
# CAUTION: Other actions depend on this name "tag-github"
tag-github:
runs-on: ubuntu-latest
if: github.repository_owner == 'onosproject'
outputs:
changed: ${{ steps.version-change.outputs.changed }}
version: ${{ steps.version-change.outputs.version }}
release_branch: ${{ steps.version-change.outputs.release_branch }}
version_branch: ${{ steps.version-change.outputs.version_branch }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changes
id: version-file
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep VERSION; then
echo "changed=true" >> $GITHUB_OUTPUT
version_before=$(git show ${{ github.event.before }}:VERSION)
echo "version_before=$version_before" >> $GITHUB_OUTPUT
else
echo "VERSION file was not changed"
fi
- name: Validate change in version file
id: version-change
if: steps.version-file.outputs.changed == 'true'
run: |
version=$(cat VERSION)
version_before_full=${{ steps.version-file.outputs.version_before }}
version_before=${version_before_full::-4}
echo "version=$version"
echo "version_before=$version_before"
validate="^[0-9]+\.[0-9]+\.[0-9]+$"
if [[ $version =~ $validate ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
else
echo "Version change not for release"
fi
if [[ $version_before =~ $validate ]]; then
IFS='.' read -r major minor patch <<< "$version"
IFS='.' read -r major_b minor_b patch_b <<< "$version_before"
if [[ "$major" -ne "$major_b" ]] || [[ "$minor" -ne "$minor_b" ]]; then
version_branch="$major_b.$minor_b"
echo "release_branch=true" >> $GITHUB_OUTPUT
echo "version_branch=$version_branch" >> $GITHUB_OUTPUT
fi
else
echo "Version change not for branch release"
fi
- name: Create release using REST API
if: steps.version-change.outputs.changed == 'true'
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{
"tag_name": "v${{ steps.version-change.outputs.version }}",
"target_commitish": "${{ github.event.repository.default_branch }}",
"name": "v${{ steps.version-change.outputs.version }}",
"draft": false,
"prerelease": false,
"generate_release_notes": true
}'
#release-image:
# runs-on: ubuntu-latest
# needs: tag-github
# if: needs.tag-github.outputs.changed == 'true'
# env:
# REGISTRY: docker.io
# DOCKER_REPOSITORY: onosproject/
# steps:
# - uses: actions/checkout@v4
#
# - uses: actions/setup-go@v5
# with:
# go-version-file: 'go.mod'
#
# - uses: docker/login-action@v3.1.0
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
#
# - name: Build and push release Docker image
# env:
# DOCKER_TAG: ${{ needs.tag-github.outputs.version }}
# run: |
# git clone https://github.com/onosproject/build-tools.git build/build-tools
# make images
# docker push ${{ env.DOCKER_REPOSITORY }}onos-kpimon:${{ env.DOCKER_TAG }}
update-version:
runs-on: ubuntu-latest
needs: tag-github
if: needs.tag-github.outputs.changed == 'true'
steps:
- uses: actions/checkout@v4
- name: Increment version
run: |
version=${{ needs.tag-github.outputs.version }}
IFS='.' read -r major minor patch <<< "$version"
patch_update=$((patch+1))
NEW_VERSION="$major.$minor.$patch_update-dev"
echo $NEW_VERSION > VERSION
echo "Updated version: $NEW_VERSION"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GH_TOKEN }}
commit-message: Update version
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: version-update
delete-branch: true
title: Update version
body: |
Update VERSION file
add-paths: |
VERSION
branch-release:
runs-on: ubuntu-latest
needs: tag-github
if: (needs.tag-github.outputs.changed == 'true') && (needs.tag-github.outputs.release_branch == 'true')
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: peterjgrainger/action-create-branch@v3.0.0
with:
branch: "rel-${{ needs.tag-github.outputs.version_branch }}"
sha: '${{ github.event.pull_request.head.sha }}'