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

Gfranxman/354 semanic release failure workaround #399

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 20 additions & 2 deletions .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ jobs:
runs-on: ubuntu-latest
environment: dev
steps:
- uses: actions/checkout@v3
- name: Prepare workaround
# Create a GitHub App token to authenticate as the workaround app.
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.CI_VERSION_WORKAROUND_APP_ID }}
private-key: ${{ secrets.CI_VERSION_WORKAROUND_APP_PRIVATE_KEY }}

- name: Checkout
# Use the workaround app-token to pull all history and tags for the repository.
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
persist-credentials: false

- name: Setup Node.js
Expand All @@ -26,6 +38,12 @@ jobs:
run: npm audit signatures

- name: Run Semantic Release
# Use the workaround app-token to authenticate as the workaround app in order to
# push tags to the protected branch.
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
# Deprecated in favor of the app token.
#CI_VERSION_WORKAROUND_APP_ID: ${{ vars.CI_VERSION_WORKAROUND_APP_ID }}
#CI_VERSION_WORKAROUND_APP_PRIVATE_KEY: ${{ secrets.CI_VERSION_WORKAROUND_APP_PRIVATE_KEY }}
#GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }} # I think this is deprecated in favor of the app token
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
90 changes: 73 additions & 17 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ PREFERRED_BIN_FOLDER=${PREFERRED_BIN_FOLDER:-"${HOME}/.local/bin"}
DESTINATION="${PREFERRED_BIN_FOLDER}/scaf"


# These are dependencies that we depend on the user to have installed:
dependencies="bash>=4.0 curl>=8.7.0 make>=3.8 python3>=3.6 docker>=19.0 git>=2.0 rsync>=3.2.0"
# ^^ Must be in the format of "name>=version" or just "name" if no version is required.

ensure_bin_folder() {
if [ ! -d "$PREFERRED_BIN_FOLDER" ]; then
echo "Creating $PREFERRED_BIN_FOLDER..."
Expand All @@ -32,27 +36,76 @@ command_exists() {
command -v "$1" > /dev/null 2>&1
}

version_compare() {
installed="$1"
required="$2"

IFS='.'
set -- $installed
installed_parts="$@"
set -- $required
required_parts="$@"
unset IFS

i=1
for req in $required_parts; do
inst=$(echo "$installed_parts" | cut -d' ' -f$i)
if [ "${inst:-0}" -lt "$req" ]; then
return 1
elif [ "${inst:-0}" -gt "$req" ]; then
return 0
fi
i=$((i + 1))
done

return 0
}

version_satisfies() {
name="$1"
required="$2"

installed_version=$("$name" --version | grep -oE '[0-9]+(\.[0-9]+)+' | head -n 1)
if [ -z "$installed_version" ]; then
return 1
fi

if ! version_compare "$installed_version" "$required"; then
return 1
fi

return 0
}

check_top_level_dependencies() {
# these are dependencies that we depend on the user to have installed
dependencies="bash curl make python3 docker git rsync"
missing=""

for dep in $dependencies; do
if ! command_exists $dep ; then
missing="$missing $dep"
name=$(echo "$dep" | cut -d'>' -f1)
version=$(echo "$dep" | grep -o '[0-9.]\+$')

if ! command_exists "$name"; then
missing="$missing $name"
elif [ -n "$version" ]; then
if ! version_satisfies "$name" "$version"; then
detected_version=$("$name" --version | grep -oE '[0-9]+(\.[0-9]+)+' | head -n 1)
missing="$missing\n$name>=$version but found $detected_version"
fi
fi
done

if [ -z "$missing" ]; then
echo "All top-level dependencies are installed and meet the required versions."
exit 0
fi

echo "The following dependencies are missing or do not meet the required versions:"
echo $missing

if [ -z "$missing" ]; then
echo "All top-level dependencies are installed."
return 0
fi

echo "The following dependencies are missing:"
for dep in $missing; do
echo "- $dep"
done

os=$(uname -s 2>/dev/null || echo "Unknown")
if [ "$os" = "Linux" ] && [ -f /proc/version ] && grep -qi microsoft /proc/version; then
os="WSL"
Expand All @@ -62,42 +115,45 @@ check_top_level_dependencies() {

# TODO: I wonder if we should look for nix, brew, apt-get, yum, etc. and provide instructions
# for those rather then strictly by OS.
for dep in $missing; do

# Process $missing line by line instead of word by word.
echo "$missing" | while IFS= read -r dep; do
[ -z "$dep" ] && continue # Skip empty lines.
case $dep in
"bash")
bash*)
echo "Please install bash for consistent shell execution."
;;
"curl")
curl*)
echo "Please install curl:"
echo " - Ubuntu/Debian: sudo apt-get install curl"
echo " - CentOS/Fedora: sudo yum install curl"
echo " - macOS: brew install curl"
echo " - Windows: Download from https://curl.se/windows/"
;;
"make")
make*)
echo "Please install make:"
echo " - Ubuntu/Debian: sudo apt-get install make"
echo " - CentOS/Fedora: sudo yum install make"
echo " - macOS: xcode-select --install"
echo " or: brew install make"
echo " - Windows: Install MinGW or use WSL"
;;
"python3")
python3*)
echo "Please install python3:"
echo " - Ubuntu/Debian: sudo apt-get install python3"
echo " - CentOS/Fedora: sudo yum install python3"
echo " - macOS: brew install python"
echo " - Windows: Download from https://www.python.org/downloads/windows/"
;;
"rsync")
rsync*)
echo "Please install rsync:"
echo " - Ubuntu/Debian: sudo apt-get install rsync"
echo " - CentOS/Fedora: sudo yum install rsync"
echo " - macOS: brew install rsync"
echo " - Windows: Can be obtained from https://www.itefix.net/cwrsync"
echo " or: Install WSL and usesudo apt-get install rsync"
;;
"docker")
docker*)
case $os in
"Darwin")
echo "Please install Docker Desktop for macOS:"
Expand Down
Loading