Skip to content

Commit 7a06476

Browse files
committed
ci: add GitHub Actions workflow to trigger GitLab CI
Force-push the PR branch to GitLab as PR-<number>, which triggers the generated .gitlab-ci.yml pipeline. Status is reported back to GitHub. Follow the established osbuild-composer pattern. Also add minimal .gitlab-ci.yml placeholder. Assisted-by: Claude Code Signed-off-by: Tomáš Hozza <thozza@redhat.com>
1 parent 2dfc568 commit 7a06476

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This workflow runs on PRs and the merge queue and is responsible for starting
2+
# the "Start GitLab CI" workflow in a way that makes it possible to use
3+
# secrets. The workflow first runs source preparation to make sure that the
4+
# gitlab-ci.yml is up to date.
5+
---
6+
name: GitLab
7+
8+
on:
9+
pull_request:
10+
branches: [main]
11+
12+
jobs:
13+
gitlab-ci-helper:
14+
name: "Gitlab CI trigger helper"
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Trigger
18+
run: echo "GitLab trigger complete"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This workflow runs on success of the GitLab workflow.
2+
# If we run it on PR or merge_group, then we can't use secrets.
3+
---
4+
name: Start GitLab CI
5+
6+
on:
7+
workflow_run:
8+
workflows: ["GitLab"]
9+
types: [completed]
10+
11+
jobs:
12+
trigger-gitlab:
13+
# this should never fail, but check it anyway in case we ever change it
14+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
15+
runs-on: ubuntu-24.04
16+
env:
17+
IMAGEBUILDER_BOT_GITLAB_SSH_KEY: ${{ secrets.IMAGEBUILDER_BOT_GITLAB_SSH_KEY }}
18+
steps:
19+
- name: Report status
20+
uses: haya14busa/action-workflow_run-status@v1
21+
22+
- name: Apt update
23+
run: sudo apt update
24+
25+
- name: Install Dependencies
26+
run: |
27+
sudo apt install -y jq
28+
29+
- name: Clone repository
30+
uses: actions/checkout@v6
31+
with:
32+
ref: ${{ github.event.workflow_run.head_sha }}
33+
fetch-depth: 0
34+
35+
- name: Get open PRs
36+
# Since this workflow doesn't run on a PR trigger, we need to find the
37+
# PR number by querying the GH API and selecting on the commit ID
38+
uses: octokit/request-action@v2.x
39+
id: fetch_pulls
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
with:
43+
route: GET /repos/${{ github.repository }}/pulls
44+
per_page: 100
45+
46+
- name: Checkout branch
47+
id: pr_data
48+
env:
49+
BRANCH: ${{ github.event.workflow_run.head_branch }}
50+
run: |
51+
PR_DATA=$(mktemp)
52+
# use uuid as a file terminator to avoid conflicts with data content
53+
cat > "$PR_DATA" <<'a21b3e7f-d5eb-44a3-8be0-c2412851d2e6'
54+
${{ steps.fetch_pulls.outputs.data }}
55+
a21b3e7f-d5eb-44a3-8be0-c2412851d2e6
56+
57+
PR=$(jq -rc '.[] | select(.head.sha | contains("${{ github.event.workflow_run.head_sha }}")) | select(.state | contains("open"))' "$PR_DATA" | jq -r .number)
58+
if [ ! -z "$PR" ]; then
59+
# Create branch named PR-<number> to push to GitLab
60+
echo "pr_branch=PR-$PR" >> "$GITHUB_OUTPUT"
61+
git checkout -b PR-$PR
62+
else
63+
git checkout "${BRANCH}"
64+
fi
65+
66+
- name: Push to GitLab
67+
run: |
68+
mkdir -p ~/.ssh
69+
echo "${IMAGEBUILDER_BOT_GITLAB_SSH_KEY}" > ~/.ssh/id_rsa
70+
chmod 400 ~/.ssh/id_rsa
71+
touch ~/.ssh/known_hosts
72+
ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts
73+
git remote add ci git@gitlab.com:redhat/services/products/image-builder/ci/bootc-foundry.git
74+
git push -f ci

.gitlab-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
stages:
3+
- test
4+
5+
no-op:
6+
stage: test
7+
script:
8+
- echo "no-op"

0 commit comments

Comments
 (0)