feat: Add GitLab CI brick CI workflow #40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 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: Create Merge Request | |
working-directory: formigas-gitlab-ci-brick-ci | |
run: | | |
git checkout -b ${{ env.branch_name }} | |
git add . | |
git commit -m "Update GitLab CI configuration for GitLab CI brick PR ${{ github.event.pull_request.number }}" | |
git push -u origin ${{ env.branch_name }} | |
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" | |
}' \ | |
"https://git.dev.formigas.de/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/merge_requests" | |
- name: Set auto-merge for Merge Request | |
working-directory: formigas-gitlab-ci-brick-ci | |
run: | | |
MR_IID=$(curl --header "PRIVATE-TOKEN: ${{ env.GITLAB_TOKEN }}" "https://git.dev.formigas.de/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/merge_requests?state=opened&source_branch=${{ env.branch_name }}" | jq '.[0].iid') | |
curl --request PUT \ | |
--header "PRIVATE-TOKEN: ${{ env.GITLAB_TOKEN }}" \ | |
--header "Content-Type: application/json" \ | |
--data '{"merge_when_pipeline_succeeds": true}' \ | |
"https://git.dev.formigas.de/api/v4/projects/${{ env.GITLAB_PROJECT_ID }}/merge_requests/$MR_IID/merge" |