Skip to content

feat: Add GitLab CI brick CI workflow #44

feat: Add GitLab CI brick CI workflow

feat: Add GitLab CI brick CI workflow #44

name: formigas_gitlab_ci brick CI
on:
pull_request:
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'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
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"
GITLAB_TOKEN: ${{ secrets.GITLAB_CI_BRICK_TEST_REPO_TOKEN }}
steps:
- name: Checkout brick repository
uses: actions/checkout@v4
with:
path: formigas-flutter-bricks
- name: Setup SSH key
uses: webfactory/[email protected]
with:
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: 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
- name: Initialize Mason
run: mason init
- name: Add formigas_gitlab_ci with Mason
run: mason add formigas_gitlab_ci --path ./formigas-flutter-bricks/formigas_gitlab_ci
- name: Make formigas_gitlab_ci
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: Create Merge Request
working-directory: formigas-gitlab-ci-brick-ci
run: |
response=$(curl --request POST \
--header "PRIVATE-TOKEN: ${{ env.GITLAB_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 "%{http_code}" \
--silent \
--output /dev/null \
"https://git.dev.formigas.de/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/merge_requests")
if [ "$response" -ge 200 ] && [ "$response" -lt 300 ]; then
echo "Merge request created successfully. Status code: $response"
else
echo "Failed to create merge request. Status code: $response"
exit 1
fi