Skip to content

Commit b01effc

Browse files
authored
feat: Github Workflows reworked for OCM
1 parent 4a78e2d commit b01effc

File tree

8 files changed

+494
-96
lines changed

8 files changed

+494
-96
lines changed

.github/workflows/build_verify.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Build and Verify
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
workflow_dispatch: {}
9+
# push:
10+
# branches:
11+
# - main
12+
# paths:
13+
# - "**/helmfile/**"
14+
# - "**/component-constructor.yaml"
15+
pull_request:
16+
branches:
17+
- main
18+
19+
permissions:
20+
pull-requests: write
21+
contents: write
22+
packages: write
23+
actions: write
24+
checks: write
25+
statuses: write
26+
27+
env:
28+
DOMAIN: "opendesk.internal"
29+
30+
jobs:
31+
expose-env-vars:
32+
name: Expose Environment Variables
33+
runs-on: [ubuntu-latest]
34+
outputs:
35+
domain: ${{ env.DOMAIN }}
36+
steps:
37+
- run: echo "domain=${{ env.DOMAIN }}"
38+
get-version:
39+
name: Get OCM Version
40+
uses: ./.github/workflows/re-get-version.yml
41+
find-constructors:
42+
name: Find Component Constructors
43+
uses: ./.github/workflows/re-find-constructors.yml
44+
publish-ocm:
45+
name: Publish OCM Packages
46+
needs:
47+
- get-version
48+
- find-constructors
49+
uses: ./.github/workflows/re-publish-ocm.yaml
50+
with:
51+
files: ${{ needs.find-constructors.outputs.files }}
52+
dry-run: true
53+
version: ${{ needs.get-version.outputs.version }}
54+
oci_registry: ghcr.io
55+
secrets:
56+
oci_reg_username: ${{ github.actor }}
57+
oci_reg_password: ${{ secrets.GITHUB_TOKEN }}
58+
set-pr-status:
59+
name: Set PR Status
60+
if: ${{ github.event_name == 'pull_request' }}
61+
needs:
62+
- publish-ocm
63+
runs-on: [ubuntu-latest]
64+
steps:
65+
- name: Get commit SHA
66+
run: echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
67+
- name: Set commit status
68+
uses: myrotvorets/set-commit-status-action@master
69+
if: always()
70+
with:
71+
allowForks: true
72+
status: ${{ job.status }}
73+
sha: ${{ env.commit }}
74+
targetUrl: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

.github/workflows/ocm-component-check.yml

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: OCM Package & Transfer
2+
3+
run-name: >-
4+
${{ github.event_name == 'workflow_dispatch'
5+
&& format('Manual release: {0}', inputs.version)
6+
|| format('Automatic release') }}
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
10+
cancel-in-progress: true
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
version:
16+
description: 'The version to set/publish the OCM packages as. E.g., "1.2.3". If not provided, the version will be auto-incremented based on the latest existing tag.'
17+
required: false
18+
type: string
19+
# To ensure this workflow only runs after successful PR checks via "Build and Verify" workflow, you must:
20+
# - block direct pushes to main by enabling branch protection rules
21+
# - require "Build and Verify" workflow to pass before merging and uncomment the 'push' trigger below.
22+
# This way we can be sure that all changes go through the PR process.
23+
push:
24+
branches:
25+
- main
26+
paths:
27+
- "**/helmfile/**"
28+
- "**/component-constructor.yaml"
29+
# Alternatively, disable the 'push' trigger and use 'workflow_run' to ensure this workflow is triggered by the "Build and Verify" workflow.
30+
# workflow_run:
31+
# workflows: ["Build and Verify"]
32+
# types:
33+
# - completed
34+
# branches:
35+
# - main
36+
37+
permissions:
38+
pull-requests: write
39+
contents: write
40+
packages: write
41+
actions: write
42+
checks: write
43+
statuses: write
44+
45+
jobs:
46+
bump-version:
47+
name: Get OCM Version
48+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
49+
uses: ./.github/workflows/re-get-version.yml
50+
with:
51+
bumped: true
52+
version: ${{ github.event.inputs.version || '' }}
53+
find-constructors:
54+
name: Find Component Constructors
55+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
56+
uses: ./.github/workflows/re-find-constructors.yml
57+
publish-ocm:
58+
name: Publish OCM Packages
59+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
60+
needs:
61+
- bump-version
62+
- find-constructors
63+
uses: ./.github/workflows/re-publish-ocm.yaml
64+
with:
65+
files: ${{ needs.find-constructors.outputs.files }}
66+
dry-run: false
67+
version: ${{ needs.bump-version.outputs.version }}
68+
oci_registry: ghcr.io
69+
oci_repository: ${{ github.repository }}
70+
secrets:
71+
oci_reg_username: ${{ github.actor }}
72+
oci_reg_password: ${{ secrets.GITHUB_TOKEN }}
73+
create-release:
74+
name: Create GitHub Release
75+
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
76+
runs-on: [ubuntu-latest]
77+
needs:
78+
- bump-version
79+
- publish-ocm
80+
steps:
81+
- uses: actions/checkout@v5
82+
- name: Create a GitHub release
83+
uses: ncipollo/release-action@v1
84+
with:
85+
tag: ocm-${{ needs.bump-version.outputs.version }}
86+
name: Release ${{ needs.bump-version.outputs.version }}
87+
generateReleaseNotes: true
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Find Component Constructors
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
files:
7+
description: 'List of component-constructor.yaml files'
8+
value: ${{ jobs.find-files.outputs.files }}
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
find-files:
15+
runs-on: [ubuntu-latest]
16+
outputs:
17+
files: ${{ steps.set-matrix.outputs.files }}
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v5
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Find all component-constructor.yaml files
25+
id: set-matrix
26+
run: |
27+
files=$(find . -type f -name 'component-constructor.yaml' | jq -R -s -c 'split("\n")[:-1]')
28+
echo "files=$files" >> $GITHUB_OUTPUT
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Get Version
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
bumped:
7+
description: 'Whether to bump the version'
8+
type: boolean
9+
required: false
10+
default: false
11+
version:
12+
description: 'The version to set'
13+
type: string
14+
required: false
15+
outputs:
16+
version:
17+
description: 'The new version'
18+
value: ${{ jobs.bump-version.outputs.version }}
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
bump-version:
25+
runs-on: [ubuntu-latest]
26+
outputs:
27+
version: ${{ steps.print-version.outputs.version }}
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v5
31+
with:
32+
fetch-depth: 0
33+
fetch-tags: true
34+
35+
- name: Configure Git
36+
run: |
37+
git config user.name "$GITHUB_ACTOR"
38+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
39+
40+
- name: Get new version
41+
id: get-version
42+
run: |
43+
if [ "${{ inputs.bumped }}" = "false" ]; then
44+
echo "VERSION=$(make print-ocm-version)" >> $GITHUB_ENV
45+
else
46+
echo "VERSION=$(make print-ocm-version-bumped)" >> $GITHUB_ENV
47+
fi
48+
if: ${{ inputs.version == '' }}
49+
50+
- name: Validate provided version
51+
id: validate-version
52+
run: |
53+
set -e
54+
echo "${{ inputs.version }}" | grep -P '^[v]?(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
55+
if: ${{ inputs.version != '' }}
56+
57+
- name: Set provided version
58+
id: set-version
59+
run: |
60+
set -e
61+
62+
# Normalize version by padding with .0 if needed
63+
VERSION="${{ inputs.version }}"
64+
# Remove 'v' prefix if present
65+
VERSION=${VERSION#v}
66+
67+
# Split version into parts (before any pre-release or build metadata)
68+
BASE_VERSION=$(echo "$VERSION" | cut -d'-' -f1 | cut -d'+' -f1)
69+
# Get everything after the base version (pre-release and build metadata)
70+
SUFFIX=$(echo "$VERSION" | sed "s/^$BASE_VERSION//")
71+
72+
# Count dots in base version
73+
DOT_COUNT=$(echo "$BASE_VERSION" | tr -cd '.' | wc -c)
74+
75+
# Pad with .0 if needed
76+
if [ $DOT_COUNT -eq 0 ]; then
77+
# Only major version provided (e.g., "1" -> "1.0.0")
78+
NORMALIZED_VERSION="$BASE_VERSION.0.0$SUFFIX"
79+
elif [ $DOT_COUNT -eq 1 ]; then
80+
# Major and minor provided (e.g., "1.2" -> "1.2.0")
81+
NORMALIZED_VERSION="$BASE_VERSION.0$SUFFIX"
82+
else
83+
# Already has 3 or more components, don't change
84+
NORMALIZED_VERSION="$VERSION"
85+
fi
86+
87+
# error if tag already exists
88+
! git tag -l | grep "ocm-$NORMALIZED_VERSION"
89+
echo "VERSION=$NORMALIZED_VERSION" >> $GITHUB_ENV
90+
if: ${{ inputs.version != '' }}
91+
92+
- name: Print version
93+
id: print-version
94+
run: |
95+
echo "version=${{ env.VERSION }}" >> $GITHUB_OUTPUT
96+
echo "New OCM version: ${{ env.VERSION }}"

0 commit comments

Comments
 (0)