Skip to content

Commit

Permalink
Merge pull request #10 from turkenf/add-publish-art
Browse files Browse the repository at this point in the history
Add own Publish Service Artifacts workflow
  • Loading branch information
turkenf authored Nov 21, 2024
2 parents d59f118 + 1f5dadc commit 0fff282
Showing 1 changed file with 151 additions and 14 deletions.
165 changes: 151 additions & 14 deletions .github/workflows/publish-service-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,167 @@
name: Publish Service Artifacts

on:
workflow_dispatch:
workflow_dispatch:
inputs:
ref:
description: "The branch, tag or SHA to checkout"
default: 'main'
required: false
type: string
subpackages:
description: 'Subpackages to be built individually (e.g. monolith config ec2)'
default: 'monolith'
default: 'config'
required: false
type: string
regorg:
description: 'Package registry and organization where the packages will be pushed (e.g. xpkg.upbound.io/upbound)'
default: 'xpkg.upbound.io/upbound'
required: false
type: string
size:
description: "Number of smaller provider packages to build and push with each build job"
description: "Number of packages to build and push with each matrix build job"
default: '30'
required: true
type: string
concurrency:
description: "Number of parallel package builds within each build job"
description: "Number of parallel package builds in each matrix job"
default: '1'
required: false
type: string
branch_name:
description: "Branch name to use while publishing the packages"
default: ''
required: false
type: string
version:
description: "Version string to use while publishing the packages"
default: ''
required: false
type: string
go-version:
description: 'Go version to use if building needs to be done'
default: '1.21'
required: false
type: string
cleanup-disk:
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"
required: false
type: boolean
default: false

env:
# Common versions
DOCKER_BUILDX_VERSION: 'v0.8.2'
UP_VERSION: 'v0.24.2'

# Common users
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}

jobs:
index:
runs-on: ubuntu-22.04
outputs:
indices: ${{ steps.calc.outputs.indices }}
steps:
- id: calc
run: |
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"
publish-service-artifacts:
uses: upbound/official-providers-ci/.github/workflows/provider-publish-service-artifacts.yml@standard-runners
with:
subpackages: ${{ github.event.inputs.subpackages }}
size: ${{ github.event.inputs.size }}
concurrency: ${{ github.event.inputs.concurrency }}
go-version: 1.21
cleanup-disk: true
secrets:
UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR_RC }}
UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW_RC }}
strategy:
matrix:
index: ${{ fromJSON(needs.index.outputs.indices) }}

needs: index
runs-on: ubuntu-22.04
steps:
- name: Cleanup Disk
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
if: ${{ github.event.inputs.cleanup-disk }}
with:
android: true
dotnet: true
haskell: true
tool-cache: true
large-packages: false
swap-storage: false

- name: Setup QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
with:
platforms: all

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2
with:
version: ${{ env.DOCKER_BUILDX_VERSION }}
install: true

- name: Login to Upbound
if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != ''
env:
UP_TOKEN: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}
run: |
curl -fsSLo /tmp/up --create-dirs 'https://cli.upbound.io/stable/${{ env.UP_VERSION }}/bin/linux_amd64/up' && \
chmod +x /tmp/up && \
/tmp/up login
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
submodules: true
ref: ${{ github.event.inputs.ref }}
token: ${{ secrets.UPBOUND_GITHUB_BOT_TOKEN }}

- name: Fetch History
run: git fetch --prune --unshallow

- name: Setup Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3
with:
go-version: ${{ github.event.inputs.go-version }}

- name: Find the Go Build Cache
id: go_cache
run: |
echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT && \
echo "mod_cache=$(make go.mod.cachedir)" >> $GITHUB_OUTPUT
- name: Cache the Go Build Cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: ${{ steps.go_cache.outputs.cache }}
key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-build-publish-artifacts-

- name: Cache Go Dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: ${{ steps.go_cache.outputs.mod_cache }}
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-pkg-

- name: Vendor Dependencies
run: make vendor vendor.check

- name: Calculate packages to build & push
id: packages
run: |
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"
- name: Build Artifacts
id: build_artifacts
run: |
packages=($(echo ${{ steps.packages.outputs.target }} | tr ' ' '\n'))
num_packages=${#packages[@]}
if [ $num_packages -gt 10 ]; then
num_packages=10
fi
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
echo "num_packages=$num_packages" >> $GITHUB_OUTPUT
env:
BUILD_ARGS: "--load"

- name: Publish Artifacts
run: |
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 comments on commit 0fff282

Please sign in to comment.