Skip to content

Commit 1f5dadc

Browse files
committed
Add own Publish Service Artifacts workflow
Signed-off-by: Fatih Türken <[email protected]>
1 parent deb670a commit 1f5dadc

File tree

1 file changed

+151
-14
lines changed

1 file changed

+151
-14
lines changed

.github/workflows/publish-service-artifacts.yml

Lines changed: 151 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,167 @@
55
name: Publish Service Artifacts
66

77
on:
8-
workflow_dispatch:
8+
workflow_dispatch:
99
inputs:
10+
ref:
11+
description: "The branch, tag or SHA to checkout"
12+
default: 'main'
13+
required: false
14+
type: string
1015
subpackages:
1116
description: 'Subpackages to be built individually (e.g. monolith config ec2)'
12-
default: 'monolith'
17+
default: 'config'
18+
required: false
19+
type: string
20+
regorg:
21+
description: 'Package registry and organization where the packages will be pushed (e.g. xpkg.upbound.io/upbound)'
22+
default: 'xpkg.upbound.io/upbound'
1323
required: false
24+
type: string
1425
size:
15-
description: "Number of smaller provider packages to build and push with each build job"
26+
description: "Number of packages to build and push with each matrix build job"
1627
default: '30'
1728
required: true
29+
type: string
1830
concurrency:
19-
description: "Number of parallel package builds within each build job"
31+
description: "Number of parallel package builds in each matrix job"
2032
default: '1'
2133
required: false
34+
type: string
35+
branch_name:
36+
description: "Branch name to use while publishing the packages"
37+
default: ''
38+
required: false
39+
type: string
40+
version:
41+
description: "Version string to use while publishing the packages"
42+
default: ''
43+
required: false
44+
type: string
45+
go-version:
46+
description: 'Go version to use if building needs to be done'
47+
default: '1.21'
48+
required: false
49+
type: string
50+
cleanup-disk:
51+
description: "If set to true, an initial step will be run to reclaim some extra disk space for the build/test jobs in this workflow"
52+
required: false
53+
type: boolean
54+
default: false
55+
56+
env:
57+
# Common versions
58+
DOCKER_BUILDX_VERSION: 'v0.8.2'
59+
UP_VERSION: 'v0.24.2'
60+
61+
# Common users
62+
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
2263

2364
jobs:
65+
index:
66+
runs-on: ubuntu-22.04
67+
outputs:
68+
indices: ${{ steps.calc.outputs.indices }}
69+
steps:
70+
- id: calc
71+
run: |
72+
python3 -c "import math; print(f'indices={list(range(0, math.ceil(len(\"${{ github.event.inputs.subpackages }}\".split()) / int(\"${{ github.event.inputs.size }}\"))))}')" >> "$GITHUB_OUTPUT"
73+
2474
publish-service-artifacts:
25-
uses: upbound/official-providers-ci/.github/workflows/provider-publish-service-artifacts.yml@standard-runners
26-
with:
27-
subpackages: ${{ github.event.inputs.subpackages }}
28-
size: ${{ github.event.inputs.size }}
29-
concurrency: ${{ github.event.inputs.concurrency }}
30-
go-version: 1.21
31-
cleanup-disk: true
32-
secrets:
33-
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR_RC }}
34-
UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW_RC }}
75+
strategy:
76+
matrix:
77+
index: ${{ fromJSON(needs.index.outputs.indices) }}
78+
79+
needs: index
80+
runs-on: ubuntu-22.04
81+
steps:
82+
- name: Cleanup Disk
83+
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
84+
if: ${{ github.event.inputs.cleanup-disk }}
85+
with:
86+
android: true
87+
dotnet: true
88+
haskell: true
89+
tool-cache: true
90+
large-packages: false
91+
swap-storage: false
92+
93+
- name: Setup QEMU
94+
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
95+
with:
96+
platforms: all
97+
98+
- name: Setup Docker Buildx
99+
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
100+
with:
101+
version: ${{ env.DOCKER_BUILDX_VERSION }}
102+
install: true
103+
104+
- name: Login to Upbound
105+
if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
106+
env:
107+
UP_TOKEN: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}
108+
run: |
109+
curl -fsSLo /tmp/up --create-dirs 'https://cli.upbound.io/stable/${{ env.UP_VERSION }}/bin/linux_amd64/up' && \
110+
chmod +x /tmp/up && \
111+
/tmp/up login
112+
113+
- name: Checkout
114+
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
115+
with:
116+
submodules: true
117+
ref: ${{ github.event.inputs.ref }}
118+
token: ${{ secrets.UPBOUND_GITHUB_BOT_TOKEN }}
119+
120+
- name: Fetch History
121+
run: git fetch --prune --unshallow
122+
123+
- name: Setup Go
124+
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
125+
with:
126+
go-version: ${{ github.event.inputs.go-version }}
127+
128+
- name: Find the Go Build Cache
129+
id: go_cache
130+
run: |
131+
echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT && \
132+
echo "mod_cache=$(make go.mod.cachedir)" >> $GITHUB_OUTPUT
133+
134+
- name: Cache the Go Build Cache
135+
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
136+
with:
137+
path: ${{ steps.go_cache.outputs.cache }}
138+
key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }}
139+
restore-keys: ${{ runner.os }}-build-publish-artifacts-
140+
141+
- name: Cache Go Dependencies
142+
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
143+
with:
144+
path: ${{ steps.go_cache.outputs.mod_cache }}
145+
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
146+
restore-keys: ${{ runner.os }}-pkg-
147+
148+
- name: Vendor Dependencies
149+
run: make vendor vendor.check
150+
151+
- name: Calculate packages to build & push
152+
id: packages
153+
run: |
154+
echo target=$(python3 -c "print(' '.join(\"${{ github.event.inputs.subpackages }}\".split()[int(\"${{ matrix.index }}\") * int(\"${{ github.event.inputs.size }}\"): (int(\"${{ matrix.index }}\")+1) * int(\"${{ github.event.inputs.size }}\")]))") >> "$GITHUB_OUTPUT"
155+
156+
- name: Build Artifacts
157+
id: build_artifacts
158+
run: |
159+
packages=($(echo ${{ steps.packages.outputs.target }} | tr ' ' '\n'))
160+
num_packages=${#packages[@]}
161+
if [ $num_packages -gt 10 ]; then
162+
num_packages=10
163+
fi
164+
make -j $num_packages SUBPACKAGES="${{ steps.packages.outputs.target }}" XPKG_REG_ORGS="${{ github.event.inputs.regorg }}" XPKG_REG_ORGS_NO_PROMOTE="${{ github.event.inputs.regorg }}" ${{ github.event.inputs.branch_name != '' && format('BRANCH_NAME={0}', github.event.inputs.branch_name) || '' }} ${{ github.event.inputs.version != '' && format('VERSION={0}', github.event.inputs.version) || '' }} build.all
165+
echo "num_packages=$num_packages" >> $GITHUB_OUTPUT
166+
env:
167+
BUILD_ARGS: "--load"
168+
169+
- name: Publish Artifacts
170+
run: |
171+
make -j ${{ steps.build_artifacts.outputs.num_packages }} SUBPACKAGES="${{ steps.packages.outputs.target }}" XPKG_REG_ORGS="${{ github.event.inputs.regorg }}" XPKG_REG_ORGS_NO_PROMOTE="${{ github.event.inputs.regorg }}" CONCURRENCY="${{ github.event.inputs.concurrency }}" ${{ github.event.inputs.branch_name != '' && format('BRANCH_NAME={0}', github.event.inputs.branch_name) || '' }} ${{ github.event.inputs.version != '' && format('VERSION={0}', github.event.inputs.version) || '' }} publish

0 commit comments

Comments
 (0)