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

Add concurrency limit for mirroring and update gitlab ci to work with… #39

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/scripts/mirror.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

set -euo pipefail

echo "${GITHUB_EVENT_NAME}"

function git-setup() {
printf -v url "https://%s:%s@%s" \
"${GITLAB_USERNAME}" \
"${GITLAB_TOKEN}" \
"${GITLAB_REPOSITORY#https://}"
echo "git remote add mirror ${url}"
git remote add mirror ${url}
set -x
}

if test "$GITHUB_EVENT_NAME" == "create"; then
# Do nothing. Every "create" event *also* publishes a *push* event, even tags/branches created from github UI.
# Duplicate events would race and sometimes cause spurious errors.
echo "Ignoring create event, because the push event will handle updates."
elif test "$GITHUB_EVENT_NAME" == "push"; then
git-setup
git push mirror ${GITHUB_REF}:${GITHUB_REF} --force --tags
git remote remove mirror
elif test "$GITHUB_EVENT_NAME" == "workflow_run"; then
git-setup
git push mirror ${GITHUB_REF}:${GITHUB_REF} --force --tags
git remote remove mirror
elif test "$GITHUB_EVENT_NAME" == "workflow_dispatch"; then
git-setup
git push mirror ${GITHUB_REF}:${GITHUB_REF} --force --tags
git remote remove mirror
elif test "$GITHUB_EVENT_NAME" == "delete"; then
if test "$DELETED_REF_TYPE" == "tag"; then
FULL_DELETED_REF="refs/tags/$DELETED_REF"
elif test "$DELETED_REF_TYPE" == "branch"; then
FULL_DELETED_REF="refs/heads/$DELETED_REF"
else
echo "Unexpected DELETED_REF_TYPE=$DELETED_REF_TYPE, expected 'branch' or 'tag'"
exit 1
fi
git-setup
git push mirror :${FULL_DELETED_REF}
git remote remove mirror
else
echo "Got unexpected GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}"
exit 1
fi

echo "Done"
15 changes: 8 additions & 7 deletions .github/workflows/gitlab_mirroring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ on: [ push, create, delete ]

jobs:
sync:
name: Gitlab Mirroring
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: action-pack/gitlab-sync@v3
with:
username: ${{ github.actor }}
url: https://gitlab.dropsolid.com/project/mauticorg.git
token: ${{ secrets.GITLAB_MIRRORING_TOKEN }}
- name: Mirror
run: .github/scripts/mirror.sh
shell: bash
env:
GITLAB_REPOSITORY: "https://gitlab.dropsolid.com/project/mauticorg.git"
GITLAB_USERNAME: ${{ github.actor }}
GITLAB_TOKEN: ${{ secrets.GITLAB_MIRRORING_TOKEN }}
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ deploy_to_qa_1:
- >-
curl
--url 'https://admin.platform.dropsolid.com/project/mauticorg/environment/qa1/action.build?_format=json'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'"}'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'", "plugin_id": "git_reference"}'
--header 'Content-type:application/json'
--header "Authorization:Bearer ${GITLAB_API_TOKEN}"
only:
Expand All @@ -37,7 +37,7 @@ deploy_to_qa_2:
- >-
curl
--url 'https://admin.platform.dropsolid.com/project/mauticorg/environment/qa2/action.build?_format=json'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'"}'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'", "plugin_id": "git_reference"}'
--header 'Content-type:application/json'
--header "Authorization:Bearer ${GITLAB_API_TOKEN}"
only:
Expand All @@ -58,7 +58,7 @@ deploy_to_qa_3:
- >-
curl
--url 'https://admin.platform.dropsolid.com/project/mauticorg/environment/qa3/action.build?_format=json'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'"}'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'", "plugin_id": "git_reference"}'
--header 'Content-type:application/json'
--header "Authorization:Bearer ${GITLAB_API_TOKEN}"
only:
Expand All @@ -79,7 +79,7 @@ deploy_to_qa_4:
- >-
curl
--url 'https://admin.platform.dropsolid.com/project/mauticorg/environment/qa4/action.build?_format=json'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'"}'
--data '{"branch":"'"${CI_COMMIT_REF_NAME}"'", "plugin_id": "git_reference"}'
--header 'Content-type:application/json'
--header "Authorization:Bearer ${GITLAB_API_TOKEN}"
only:
Expand Down
Loading