Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add GitLab CI brick CI workflow #158

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
25 changes: 25 additions & 0 deletions .github/workflows/check-gitlab-ci-label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check GitLab CI Label

on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]
paths:
- formigas_gitlab_ci/**
- '!formigas_gitlab_ci/**/*.md'
- '!formigas_gitlab_ci/docs/**'
- .github/workflows/continuous-integration-formigas_gitlab_ci.yaml
- .github/workflows/check-gitlab-ci-label.yaml

jobs:
check-label:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Check for required label
uses: mheap/github-action-required-labels@v5
with:
mode: minimum
count: 1
labels: "gitlab-ci: success"
99 changes: 78 additions & 21 deletions .github/workflows/continuous-integration-formigas_gitlab_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,58 @@ name: formigas_gitlab_ci brick CI
on:
pull_request:
paths:
- formigas_gitlab_ci/**
- .github/workflows/continuous-integration-formigas_gitlab_ci.yaml
- 'formigas_gitlab_ci/**'
- '!formigas_gitlab_ci/**/*.md'
- '!formigas_gitlab_ci/docs/**'
- '.github/workflows/continuous-integration-formigas_gitlab_ci.yaml'
- '.github/workflows/check-gitlab-ci-label.yaml'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
create-mr-with-changes:
name: Create MR with changes in test repository
runs-on: ubuntu-latest

env:
branch_name: "formigas_gitlab_ci-changes-${{ github.event.pull_request.number }}"
GITLAB_PROJECT_ID: "251"

steps:
- name: Checkout repository
- name: Checkout brick repository
uses: actions/checkout@v4
with:
path: formigas-flutter-bricks

- name: Install Flutter
uses: subosito/flutter-action@v2
- name: Setup SSH key
uses: webfactory/[email protected]
with:
flutter-version: 3.24.2
cache: true
ssh-private-key: ${{ secrets.GITLAB_CI_BRICK_TEST_REPO_DEPLOY_KEY }}

- name: Add GitLab server to known hosts
run: |
mkdir -p ~/.ssh
echo ${{ vars.FORMIGAS_GITLAB_SERVER_PUBLIC_KEY }} >> ~/.ssh/known_hosts

- name: create flutter project
run: flutter create my_app --empty --template=app --platforms=android --no-pub
- name: Checkout GitLab CI test repository
run: |
git clone [email protected]:framework/formigas-gitlab-ci-brick-ci.git
cd formigas-gitlab-ci-brick-ci
git config user.name "GitHub Actions"
git config user.email "[email protected]"

- name: Checkout or create branch
working-directory: formigas-gitlab-ci-brick-ci
run: |
git fetch origin
git checkout -B ${{ env.branch_name }} origin/${{ env.branch_name }} || git checkout -b ${{ env.branch_name }}

- name: Install Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable

- name: Install Mason CLI
run: dart pub global activate mason_cli
Expand All @@ -34,20 +63,48 @@ jobs:
run: mason init

- name: Add formigas_gitlab_ci with Mason
run: mason add formigas_gitlab_ci --path ./formigas_gitlab_ci
run: mason add formigas_gitlab_ci --path ./formigas-flutter-bricks/formigas_gitlab_ci

- name: Make formigas_gitlab_ci
run: mason make formigas_gitlab_ci --runner_tag=my-runner-tag
working-directory: my_app
run: mason make formigas_gitlab_ci --on-conflict overwrite --runner_tag gitlab-runner-tag
working-directory: formigas-gitlab-ci-brick-ci

# - name: Commit and push changes
# working-directory: formigas-gitlab-ci-brick-ci
# run: |
# git add .
# git commit -m "Update GitLab CI configuration for GitLab CI brick PR ${{ github.event.pull_request.number }}"
# git push -f origin ${{ env.branch_name }}

- name: Verify file creation
- name: Create Merge Request
working-directory: formigas-gitlab-ci-brick-ci
run: |
if [ ! -f "gitlab-ci.yml" ]; then
echo "gitlab-ci.yml not found"
exit 1
fi
if [ ! -f "templates/build.yml" ]; then
echo "templates/build.yml not found"
response=$(curl --request POST \
--header "PRIVATE-TOKEN: ${{ secrets.GITLAB_CI_BRICK_TEST_REPO_TOKEN }}" \
--header "Content-Type: application/json" \
--data '{
"source_branch": "${{ env.branch_name }}",
"target_branch": "main",
"title": "Automated MR for GitLab CI brick changes",
"description": "This MR is automatically generated by the GitLab CI brick CI workflow. It will merge the changes made in the CI workflow into the main branch. Once the pipelines succeed, this MR will be automatically merged. See the [GitLab CI brick PR](${{ github.event.pull_request.html_url }}) for more details.",
"remove_source_branch": true,
"squash": true,
"labels": "automated-mr",
"merge_when_pipeline_succeeds": true,
"auto_merge_strategy": "merge_when_pipeline_succeeds"
}' \
--write-out "\n%{http_code}" \
"https://git.dev.formigas.de/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/merge_requests")

body=$(echo "$response" | sed '$d')
status_code=$(echo "$response" | tail -n1)

echo "Response body: $body"
echo "Status code: $status_code"

if [ "$status_code" -ge 200 ] && [ "$status_code" -lt 300 ]; then
echo "Merge request created successfully."
else
echo "Failed to create merge request."
exit 1
fi
working-directory: my_app
22 changes: 2 additions & 20 deletions formigas_gitlab_ci/__brick__/gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
variables:
FLUTTER_VERSION: "3.24.2"
FLUTTER_VERSION: "3.24.3"
FLUTTER_DOCKER_IMAGE: "ghcr.io/cirruslabs/flutter:${FLUTTER_VERSION}"

workflow:
rules:
- if: $CI_COMMIT_BRANCH == "develop" || $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "staging"
- if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"
- when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"

include:
- local: "templates/build.yml"
rules:
- if: $CI_COMMIT_BRANCH == "develop" || $CI_PIPELINE_SOURCE == "merge_request_event"
inputs:
docker_image: $FLUTTER_DOCKER_IMAGE
flavor: "development"
- local: "templates/build.yml"
rules:
- if: $CI_COMMIT_BRANCH == "staging"
inputs:
docker_image: $FLUTTER_DOCKER_IMAGE
flavor: "staging"
- local: "templates/build.yml"
rules:
- if: $CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "main"
inputs:
docker_image: $FLUTTER_DOCKER_IMAGE
flavor: "production"

stages:
- validate
Expand Down
11 changes: 4 additions & 7 deletions formigas_gitlab_ci/__brick__/templates/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ spec:
docker_image:
description: "Docker image to use for build"
type: string
flavor:
description: "Flavor to build for"
options: [development, staging, production]
---
build_ios_$[[ inputs.flavor ]]:
build_ios:
stage: build
needs: []
tags:
Expand All @@ -16,9 +13,9 @@ build_ios_$[[ inputs.flavor ]]:
script:
- flutter clean
- flutter pub run build_runner build --delete-conflicting-outputs
- flutter build ios --no-codesign --release --flavor $[[ inputs.flavor ]] -t lib/main_$[[ inputs.flavor ]].dart
- flutter build ios --no-codesign --release --flavor production -t lib/main_production.dart

build_android_$[[ inputs.flavor ]]:
build_android:
stage: build
needs: []
tags:
Expand All @@ -31,4 +28,4 @@ build_android_$[[ inputs.flavor ]]:
- curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | bash
- flutter clean
- dart run build_runner build --delete-conflicting-outputs
- flutter build appbundle --release --flavor $[[ inputs.flavor ]] -t lib/main_$[[ inputs.flavor ]].dart
- flutter build appbundle --release --flavor production -t lib/main_production.dart
Loading