Upstream sync check #3
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: Sync fork | |
#on: | |
# schedule: | |
# # actually, ~5 minutes is the highest | |
# # effective frequency you will get | |
# - cron: '* * * * *' | |
on: | |
workflow_dispatch: | |
jobs: | |
merge: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./ | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Sync fork | |
env: | |
FORK: "https://github.com/Constructor-io/zerolog-sentry" | |
UPSTREAM: "https://github.com/archdx/zerolog-sentry" | |
UPSTREAM_BRANCH: "master" | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
SLACK_MENTIONS: ${{ secrets.SLACK_MENTIONS }} | |
run: | | |
# Get SHA of the latest commit on from original Git repo (UPSTREAM). | |
UPSTREAM_SHA=$(git ls-remote $UPSTREAM $UPSTREAM_BRANCH | awk '{print $1;}') | |
echo "Upstream SHA: $UPSTREAM_SHA" | |
# Check that upstream commit can be found in our forked Git repo. (We are in sync with latest upstream). | |
FOUND_UPSTREAM_SHA=$(git cat-file -t "$UPSTREAM_SHA") | |
if [[ $FOUND_UPSTREAM_SHA == "commit" ]]; then | |
echo "$FORK in sync with latest $UPSTREAM." | |
exit 0 | |
else | |
read -r -d '' SLACK_MESSAGE <<-EOM | |
{ | |
"text": "*Issue:* FORK NOT IN SYNC WITH LATEST UPSTREAM.\n*Fork:* $FORK\n*Upstream:* $UPSTREAM\n*Upstream commit SHA:* $UPSTREAM_SHA\n*Assigned to:* $SLACK_MENTIONS", | |
} | |
EOM | |
SLACK_WEBHOOK_RESPONSE=$(curl -X POST -H 'Content-type: application/json' --data "$SLACK_MESSAGE" $SLACK_WEBHOOK_URL) | |
if [[ $SLACK_WEBHOOK_RESPONSE == "ok" ]]; then | |
echo "Slack message sent successfully." | |
exit 1 | |
else | |
echo "Slack message failed to send with error: $SLACK_WEBHOOK_RESPONSE" | |
exit 2 | |
fi | |
fi |