-
Notifications
You must be signed in to change notification settings - Fork 40
181 lines (172 loc) · 6.52 KB
/
package-release.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
name: Package Release
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
on:
workflow_dispatch:
inputs:
num-commits:
description: "The of commits to check for updated packages. If 0, the action will check all commits on the branch. For any larger value, the action will check the last n commits for any updated packages."
required: true
default: 1
type: number
ignore-missing-dev:
description: "If true, the action will ignore packages that do not have a dev version. Otherwise, the action will fail if any package does not have a dev version."
required: true
default: true
type: boolean
repo_name:
description: 'Name of the base repository. The user can ignore this input if the action is triggered from the base repository.'
required: true
type: string
default: 'image-tools'
workflow_call:
inputs:
num-commits:
description: "The of commits to check for updated packages. If 0, the action will check all commits on the master branch. For any larger value, the action will check the last n commits for any updated packages."
required: true
default: 1
type: number
ignore-missing-dev:
description: "If true, the action will ignore packages that do not have a dev version. Otherwise, the action will fail if any package does not have a dev version."
required: true
default: true
type: boolean
repo_name:
description: 'Name of the base repository'
required: true
type: string
secrets:
DOCKER_USERNAME:
description: 'Docker Hub username'
required: true
DOCKER_TOKEN:
description: 'Docker Hub password'
required: true
permissions:
contents: write
jobs:
package-filter:
name: Filter for updated packages
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}'
uses: ./.github/workflows/package-filter.yml
with:
num-commits: ${{ fromJson(github.event.inputs.num-commits) }}
ignore-missing-dev: ${{ fromJson(github.event.inputs.ignore-missing-dev) }}
package-release:
name: Release Versions
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}'
needs: package-filter
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
persist-credentials: false
- name: Token | Generate
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Token | Use the token
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh api octocat
- name: Python | Setup
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Python | Install bump2version
run: |
python -m pip install --upgrade pip
pip install bump2version
- name: Python | Bump Version Release
id: bump_version
run: |
cur_dir=$GITHUB_WORKSPACE
released_packages=""
for pkg_dir in ${{ needs.package-filter.outputs.list }}
do
echo "Bumping version for ${pkg_dir}"
cd "${pkg_dir}"
# check if the package has a dev version
if [[ "$(cat VERSION)" != *dev* ]]
then
msg="${pkg_dir} does not have a dev version"
if ${{ github.event.inputs.ignore-missing-dev }}
then
echo "::warning::${msg}"
else
echo "::error::${msg}" && exit 1
fi
else
bump2version release --no-commit --allow-dirty
released_packages="${released_packages} ${pkg_dir}"
fi
cd ${cur_dir}
done
# Trim leading whitespace
released_packages=$(echo "${released_packages}" | xargs)
echo "Released packages: ${released_packages}"
echo "released_packages=${released_packages}" >> $GITHUB_OUTPUT
- name: Git | Commit
if: steps.bump_version.outputs.released == 'true'
env:
CI_COMMIT_AUTHOR: polusai-auth-helper[bot]
CI_COMMIT_EMAIL: ${{ secrets.APP_ID }}+polusai-auth-helper[bot]@users.noreply.github.com
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git commit -a -m "build: Bumped release version for ${{ steps.bump_version.outputs.released_packages }}"
- name: Git | Push
if: steps.bump_version.outputs.released == 'true'
uses: ad-m/github-push-action@master
with:
force: true
github_token: ${{ steps.generate_token.outputs.token }}
docker:
name: Docker | ${{ matrix.package_name }}
if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}'
needs: [package-filter, package-release]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
persist-credentials: false
- name: Docker | Tag
id: docker_tag
run: |
package_dir="${{ matrix.package_dir }}"
cp .gitignore ${package_dir}/.dockerignore
version=$(cat ${package_dir}/VERSION)
tag=polusai/${{ matrix.package_name }}:${version}
echo "tag=${tag}" >> $GITHUB_OUTPUT
- name: Docker | Setup Buildx
uses: docker/setup-buildx-action@v3
- name: Docker | Login DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Docker | Check if Image exists
run: |
tag=${{ steps.docker_tag.outputs.tag }}
docker pull ${tag} > /dev/null \
&& $(echo "::error::${tag} already exists on DockerHub" && exit 1) \
|| echo "success"
- name: Docker | Push Image
uses: docker/build-push-action@v5
with:
context: "{{defaultContext}}:${{ matrix.package_dir }}"
push: true
tags: ${{ steps.docker_tag.outputs.tag }}