-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-release.sh
More file actions
executable file
·51 lines (44 loc) · 2.2 KB
/
push-release.sh
File metadata and controls
executable file
·51 lines (44 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#################################################################################################################################
# build-release.sh
# Created on 03/27/2025
#
# Copyright (C) 2025 Mehmet Bertan Tarakcioglu, Under the MIT License
#
# This file was originally created as part of the WatchDuck project CI Pipeline.
#################################################################################################################################
# This script is meant to run on a GitHub macOS Action Runner as part of the Swift-Executable-CI workflows!
# It assumes to be part of the workflow and may fail if it is being run by itself.
# Just before creating a new release, this script will push the changes to the changelog to the repo.
# It wil then create the new tag and also push it.
# Exit bash script on error
set -eo pipefail
# Set up git credentials as the GitHub Actions Bot
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Try and find a changelog file in the repo
CHANGELOG_FILE=$(find . -maxdepth 1 -type f -iname "changelog*" | head -1)
MATCH_COUNT=$(echo "${CHANGELOG_FILE}" | wc -l | xargs)
# Make sure there is only one
if [[ "${MATCH_COUNT}" -lt 1 ]]; then
echo "Warning: No CHANGELOG file found! Skipping commit."
elif [[ "${MATCH_COUNT}" -gt 1 ]]; then
echo "Warning: More than one CHANGELOG file found! Skipping commit."
else
git add "${CHANGELOG_FILE}"
# Make sure the changelog file actually has changes to commit...
if ! git diff --cached --quiet; then
# Use the API here so the commit and push is signed by GitHub
gh api --method PUT /repos/"${REPO_PATH}"/contents/"${CHANGELOG_FILE}" \
--field message="Update changelog for release ${NEW_TAG}" \
--field content="$( base64 -w 0 -i "${CHANGELOG_FILE}" )" \
--field encoding="base64" \
--field branch="${TARGET_BRANCH}" \
--field sha="$( git rev-parse "${TARGET_BRANCH}":"${CHANGELOG_FILE}" )"
else
echo "Warning: No changes found in the CHANGELOG file! Skipping commit."
fi
fi
# Create and push the new tag
git tag "${NEW_TAG}"
git push --atomic origin "${NEW_TAG}"