Skip to content

Commit

Permalink
feat(gitlab): add CI component
Browse files Browse the repository at this point in the history
This adds a GitLab CI/CD component that can be `included` in users
GitLab CI configuration to integrate releaser-pleaser.

Unlike the GitHub Action, this can not easily run whenever a merge
request description is changed, only when changes are pushed to main.

We also switch the container base image from `static` to `busybox`
as GitLab CI requires a shell (`sh`) binary to be present for the image
use to run jobs.
  • Loading branch information
apricote committed Sep 15, 2024
1 parent 84d4dd9 commit 192f225
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/mirror.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: mirror
on:
push:
branches: [main, gitlab] # TODO
tags: ["*"]

jobs:
gitlab:
runs-on: ubuntu-latest
env:
REMOTE: mirror
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Need all to fetch all tags so we can push them
fetch-depth: 0

- name: Add Remote
env:
CLONE_URL: "https://releaser-pleaser:${{ secrets.GITLAB_COM_PUSH_TOKEN }}@gitlab.com/apricote/releaser-pleaser.git"
run: git remote add $REMOTE $CLONE_URL

- name: Push Branches
run: git push --force --all --prune --verbose $REMOTE

- name: Push Tags
run: git push --force --tags --verbose $REMOTE
15 changes: 15 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
stages: [release]

# For the GitLab CI/CD component to be usable, it needs to be published in
# the CI/CD catalog. This happens on new releases.
# As the primary tagging happens on GitHub, we only react to pushed tags
# and create a corresponding GitLab Release.
create-release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
script: echo "Creating release $CI_COMMIT_TAG"
rules:
- if: $CI_COMMIT_TAG
release:
tag_name: "$CI_COMMIT_TAG"
description: "$CI_COMMIT_TAG_MESSAGE"
5 changes: 4 additions & 1 deletion .ko.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
defaultPlatforms:
- linux/arm64
- linux/amd64
- linux/amd64

# Need a shell for gitlab-ci
defaultBaseImage: cgr.dev/chainguard/busybox
4 changes: 2 additions & 2 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Tutorials

- [Getting started on GitHub](tutorials/github.md)
- [Getting started on GitLab]()
- [Getting started on GitLab](tutorials/gitlab.md)

# Explanation

Expand All @@ -22,7 +22,7 @@
- [Glossary](reference/glossary.md)
- [Pull Request Options](reference/pr-options.md)
- [GitHub Action](reference/github-action.md)
- [GitLab CI]()
- [GitLab CI/CD Component](reference/gitlab-cicd-component.md)

---

Expand Down
1 change: 1 addition & 0 deletions docs/reference/gitlab-cicd-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# GitLab CI/CD Component
Empty file added docs/tutorials/gitlab.md
Empty file.
36 changes: 36 additions & 0 deletions templates/run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
spec:
inputs:
# Remember to update docs/reference/gitlab-ci-component.md
branch:
default: main
description: "This branch is used as the target for releases."

token:
description: "GitLab token for creating and updating release MRs."

extra-files:
description: 'List of files that are scanned for version references.'
default: ""

stage:
default: build
description: 'Defines the build stage'
# Remember to update docs/reference/gitlab-ci-component.md
---

releaser-pleaser:
stage: $[[ inputs.stage ]]
rules:
# There is no way to run a pipeline when the MR description is updated :(
- if: $CI_COMMIT_BRANCH == "$[[ inputs.branch ]]"
image:
name: ghcr.io/apricote/releaser-pleaser:v0.4.0-beta.0 # x-releaser-pleaser-version
entrypoint: [""]
variables:
GITLAB_TOKEN: $[[ inputs.token ]]
script:
- |
rp run \
--forge=gitlab \
--branch=$[[ inputs.branch ]] \
--extra-files=$[[ inputs.extra-files ]]

0 comments on commit 192f225

Please sign in to comment.