[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/imcf/scijava-scripts/master/github-actionify.sh [Back]  [Original]

#!/bin/sh

# github-actionify.sh
#
# Script for enabling or updating GitHub Action builds for a given repository.

#set -e

dir="$(dirname "$0")"

ciDir=.github
ciSlugBuild=workflows/build.yml
ciConfigBuild=$ciDir/$ciSlugBuild
ciSetupScript=$ciDir/setup.sh
ciBuildScript=$ciDir/build.sh
pomMinVersion='17.1.1'
tmpFile=github-actionify.tmp
msgPrefix="CI: "

info() { echo "- $@"; }
warn() { echo "[WARNING] $@" 1>&2; }
err() { echo "[ERROR] $@" 1>&2; }
die() { err "$@"; exit 1; }

check() {
	for tool in $@
	do
		which "$tool" >/dev/null ||
			die "The '$tool' utility is required but not found"
	done
}

update() {
	file=$1
	msg=$2
	exe=$3
	test "$msg" || msg="update $file"
	if [ -e "$file" ]
	then
		if diff -q "$file" "$tmpFile" >/dev/null
		then
			info "$file is already OK"
		else
			info "Updating $file"
			$EXEC rm -rf "$file"
			$EXEC mv -f "$tmpFile" "$file"
		fi
	else
		info "Creating $file"
		$EXEC mkdir -p "$(dirname "$file")"
		$EXEC mv "$tmpFile" "$file"
	fi
	rm -rf "$tmpFile"
	$EXEC git add "$file"
	if [ -n "$exe" ]
	then
		info "Adding execute permission to $file"
		$EXEC git update-index --chmod=+x "$file"
	fi
	$EXEC git diff-index --quiet HEAD -- || $EXEC git commit -m "$msgPrefix$msg"
}

process() {
	cd "$1"

	# -- Git sanity checks --

	repoSlug=$(grep '' pom.xml | sed 's;.*github.com[/:]\(.*/.*\).*;\1;')
	test "$repoSlug" && info "Repository = $repoSlug" || die 'Could not determine GitHub repository slug'
	case "$repoSlug" in
		*.git)
			die "GitHub repository slug ('$repoSlug') ends in '.git'; please fix the POM"
			;;
	esac
	git fetch >/dev/null
	git diff-index --quiet HEAD -- || die "Dirty working copy"
	currentBranch=$(git rev-parse --abbrev-ref HEAD)
	upstreamBranch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u})
	remote=${upstreamBranch%/*}
	defaultBranch=$(git remote show "$remote" | grep "HEAD" | sed 's/.*: //')
	test "$currentBranch" = "$defaultBranch" || die "Non-default branch: $currentBranch"
	git merge --ff --ff-only 'HEAD@{u}' >/dev/null ||
		die "Cannot fast forward (local diverging?)"
#	test "$(git rev-parse HEAD)" = "$(git rev-parse 'HEAD@{u}')" ||
#		die "Mismatch with upstream branch (local ahead?)"

	# -- POM sanity checks --

	parent=$(grep -A4 '' pom.xml | grep '' | sed 's;.*\(.*\).*;\1;')
	if [ -z "$SKIP_PARENT_CHECK" ]
	then
		test "$parent" = "pom-scijava" ||
			die "Not pom-scijava parent: $parent. Run with -p flag to skip this check."
	fi

	# Change pom.xml from Travis CI to GitHub Actions
	domain="github.com"
	sed 's/Travis CI/GitHub Actions/g' pom.xml |
		sed "s;travis-ci.*;github.com/$repoSlug/actions;g" >"$tmpFile"
	update pom.xml "switch from Travis CI to GitHub Actions"

	# -- GitHub Action sanity checks --

	test -e "$ciDir" -a ! -d "$ciDir" && die "$ciDir is not a directory"
	test -e "$ciConfigBuild" -a ! -f "$ciConfigBuild" && die "$ciConfigBuild is not a regular file"
	test -e "$ciConfigBuild" && warn "$ciConfigBuild already exists"
	test -e "$ciBuildScript" && warn "$ciBuildScript already exists"
	test -e "$ciSetupScript" && warn "$ciSetupScript already exists"

	# -- GitHub Action steps --

	actionCheckout="uses: actions/checkout@v2"
	actionSetupJava="name: Set up Java
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'zulu'
          cache: 'maven'"
	actionSetupConda="name: Set up conda
        uses: s-weigand/setup-conda@v1
      - name: Install conda packages
        run: conda env update -f environment.yml -n base"
	actionSetupCI="name: Set up CI environment
        run: $ciSetupScript"
	actionExecuteBuild="name: Execute the build
        run: $ciBuildScript"
  actionSecrets="env:
          GPG_KEY_NAME: \${{ secrets.GPG_KEY_NAME }}
          GPG_PASSPHRASE: \${{ secrets.GPG_PASSPHRASE }}
          MAVEN_USER: \${{ secrets.MAVEN_USER }}
          MAVEN_PASS: \${{ secrets.MAVEN_PASS }}
          OSSRH_USER: \${{ secrets.OSSRH_USER }}
          OSSRH_PASS: \${{ secrets.OSSRH_PASS }}
          SIGNING_ASC: \${{ secrets.SIGNING_ASC }}"

	# -- Do things --

	# Add/update the GitHub Actions build configuration file.
	cat >"$tmpFile" "$tmpFile"
	cat >>"$tmpFile" "$tmpFile"
			update pom.xml "update pom-scijava parent to $pomMinVersion"
		else
			info "Version of pom-scijava ($version) is OK"
		fi
	fi

	# ensure  section is present
	releaseProfile=$(grep '' pom.xml 2>/dev/null | sed 's/[^>]*>//' | sed 's/\n\t\t&2; break;;
	*) break;;
	esac
	shift
done

test "$EXEC" && warn "Simulation only. Run with -f flag to go for real."

# process arguments
if [ $# -gt 0 ]
then
	for d in $@
	do (
		echo "[$d]"
		process "$d"
	) done
else
	process .
fi

Web Proxy Viewer  |  New URL  |  Original Page