Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
ab274e74
Commit
ab274e74
authored
Jan 16, 2025
by
Anant Sharma
Committed by
GitHub
Jan 16, 2025
Browse files
ci: wait for mirror sync to finish before ci trigger (#25)
parent
7af0d2ef
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
6 deletions
+43
-6
.github/workflows/mirror_repo.sh
.github/workflows/mirror_repo.sh
+35
-0
.github/workflows/trigger_ci_pull.yml
.github/workflows/trigger_ci_pull.yml
+4
-3
.github/workflows/trigger_ci_push.yml
.github/workflows/trigger_ci_push.yml
+4
-3
No files found.
.github/workflows/mirror_repo.sh
0 → 100755
View file @
ab274e74
#!/bin/bash -e
# Description: This script triggers a GitLab mirror update and waits for completion
# Usage: ./update_gitlab_mirror.sh <gitlab_access_token> <gitlab_mirror_url>
GITLAB_ACCESS_TOKEN
=
$1
GITLAB_MIRROR_URL
=
$2
SYNC_TIME
=
$(
date
-u
+
"%Y-%m-%dT%H:%M:%SZ"
)
curl
--fail-with-body
--request
POST
--header
"PRIVATE-TOKEN:
${
GITLAB_ACCESS_TOKEN
}
"
"
${
GITLAB_MIRROR_URL
}
"
echo
"Mirror update request submitted at
${
SYNC_TIME
}
"
# Poll for completion
# GitLab limits the frequency of mirror updates to once every 5 mins.
# If you trigger an update more frequently, it may not start immediately.
# Make sure sync is finished after sync request was submitted
MAX_RETRIES
=
15
RETRY_INTERVAL
=
30
# Convert timestamps to epoch for comparison, timezone agnostic
SYNC_TIME_SECONDS
=
$(
date
-d
"
$SYNC_TIME
"
+%s
)
for
i
in
$(
seq
1
$MAX_RETRIES
)
;
do
MIRROR_INFO
=
$(
curl
--silent
--header
"PRIVATE-TOKEN:
${
GITLAB_ACCESS_TOKEN
}
"
"
${
GITLAB_MIRROR_URL
}
"
)
MIRROR_STATUS
=
$(
echo
"
$MIRROR_INFO
"
| jq
-r
'.update_status'
)
LAST_UPDATE
=
$(
echo
"
$MIRROR_INFO
"
| jq
-r
'.last_update_at'
)
LAST_UPDATE_SECONDS
=
$(
date
-d
"
$LAST_UPDATE
"
+%s
)
if
[
"
$MIRROR_STATUS
"
=
"finished"
]
&&
[
$LAST_UPDATE_SECONDS
-gt
$SYNC_TIME_SECONDS
]
;
then
echo
"Mirror sync successful. Last update:
$LAST_UPDATE
"
exit
0
fi
echo
"Waiting for mirror sync to complete. Attempt
$i
of
$MAX_RETRIES
"
echo
"Last update:
$LAST_UPDATE
"
sleep
$RETRY_INTERVAL
done
echo
"Mirror sync failed or timed out"
exit
1
.github/workflows/trigger_ci_pull.yml
View file @
ab274e74
...
@@ -21,10 +21,11 @@ jobs:
...
@@ -21,10 +21,11 @@ jobs:
environment
:
GITLAB
environment
:
GITLAB
runs-on
:
self-hosted
runs-on
:
self-hosted
steps
:
steps
:
-
name
:
Check out the repository to the runner
uses
:
actions/checkout@v4
-
name
:
Sync Mirror Repository
-
name
:
Sync Mirror Repository
run
:
|
run
:
./.github/workflows/mirror_repo.sh ${{ secrets.TOKEN }} ${{ secrets.MIRROR_URL }}
#!/bin/bash
curl --fail-with-body --request POST --header "PRIVATE-TOKEN: ${{ secrets.TOKEN }}" "${{ secrets.MIRROR_URL }}"
trigger-ci
:
trigger-ci
:
environment
:
GITLAB
environment
:
GITLAB
needs
:
mirror_repo
needs
:
mirror_repo
...
...
.github/workflows/trigger_ci_push.yml
View file @
ab274e74
...
@@ -23,10 +23,11 @@ jobs:
...
@@ -23,10 +23,11 @@ jobs:
environment
:
GITLAB
environment
:
GITLAB
runs-on
:
self-hosted
runs-on
:
self-hosted
steps
:
steps
:
-
name
:
Check out the repository to the runner
uses
:
actions/checkout@v4
-
name
:
Sync Mirror Repository
-
name
:
Sync Mirror Repository
run
:
|
run
:
./.github/workflows/mirror_repo.sh ${{ secrets.TOKEN }} ${{ secrets.MIRROR_URL }}
#!/bin/bash
curl --fail-with-body --request POST --header "PRIVATE-TOKEN: ${{ secrets.TOKEN }}" "${{ secrets.MIRROR_URL }}"
trigger-ci
:
trigger-ci
:
environment
:
GITLAB
environment
:
GITLAB
needs
:
mirror_repo
needs
:
mirror_repo
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment