mirror of
https://github.com/ViViDboarder/docset-sfdc.git
synced 2024-11-21 14:46:34 +00:00
Refactor of scripts to add a target for auto creating a pr
I plan to use this for automated builds
This commit is contained in:
parent
771760f828
commit
26a70dce27
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,3 +17,4 @@ build/
|
||||
archive/
|
||||
.DS_Store
|
||||
docset-gen
|
||||
repotmp/
|
||||
|
34
Makefile
34
Makefile
@ -19,30 +19,42 @@ run-lightning: clean-index
|
||||
|
||||
.PHONY: package-apex
|
||||
package-apex: run-apex
|
||||
./package-docset.sh apexcode
|
||||
./scripts/package-docset.sh apexcode
|
||||
|
||||
.PHONY: package-vf
|
||||
package-vf: run-vf
|
||||
./package-docset.sh pages
|
||||
./scripts/package-docset.sh pages
|
||||
|
||||
.PHONY: package-lightning
|
||||
package-lightning: run-lightning
|
||||
./package-docset.sh lightning
|
||||
./scripts/package-docset.sh lightning
|
||||
|
||||
.PHONY: archive-apex
|
||||
archive-apex: package-apex
|
||||
./archive-docset.sh apexcode
|
||||
./scripts/archive-docset.sh apexcode
|
||||
|
||||
./archive/Salesforce_Apex: archive-apex
|
||||
|
||||
.PHONY: archive-vf
|
||||
archive-vf: package-vf
|
||||
./archive-docset.sh pages
|
||||
./scripts/archive-docset.sh pages
|
||||
|
||||
./archive/Salesforce_Visualforce: archive-vf
|
||||
|
||||
.PHONY: archive-lightning
|
||||
archive-lightning: package-lightning
|
||||
./archive-docset.sh lightning
|
||||
./archive-lightning: package-lightning
|
||||
./scripts/archive-docset.sh lightning
|
||||
|
||||
./archive/Salesforce_Lightning: archive-lightning
|
||||
|
||||
.PHONY: archive-all
|
||||
archive-all: archive-apex archive-vf archive-lightning
|
||||
archive-all: archive-apex archive-vf # archive-lightning Lightning package isn't functional
|
||||
|
||||
./archive: archive-all
|
||||
|
||||
.PHONY: create-pr
|
||||
create-pr: ./archive
|
||||
./scripts/create-pr.sh
|
||||
|
||||
.PHONY: clean-index
|
||||
clean-index:
|
||||
@ -64,5 +76,9 @@ clean: clean-index clean-package clean-archive
|
||||
clean-build:
|
||||
rm -fr ./build
|
||||
|
||||
.PHONY: clean-pr
|
||||
clean-pr:
|
||||
rm -fr ./repotmp
|
||||
|
||||
.PHONY: clean-all
|
||||
clean-all: clean clean-build
|
||||
clean-all: clean clean-build clean-pr
|
||||
|
@ -10,7 +10,8 @@ deliverable=$1
|
||||
|
||||
function get_friendly_name {
|
||||
local deliverable=$1
|
||||
local name="$(tr '[:lower:]' '[:upper:]' <<< "${deliverable:0:1}")${deliverable:1}"
|
||||
local name
|
||||
name="$(tr '[:lower:]' '[:upper:]' <<< "${deliverable:0:1}")${deliverable:1}"
|
||||
case "$deliverable" in
|
||||
"apexcode")
|
||||
name="Apex"
|
||||
@ -34,14 +35,17 @@ function get_icon_name {
|
||||
}
|
||||
|
||||
function main {
|
||||
local name=$(get_friendly_name "$deliverable")
|
||||
local name
|
||||
name=$(get_friendly_name "$deliverable")
|
||||
local package="$out_dir/Salesforce $name.docset"
|
||||
local archive_dir="$archive_dir/Salesforce_$name"
|
||||
local archive="$archive_dir/Salesforce_$name.tgz"
|
||||
local icon=$(get_icon_name "$deliverable")
|
||||
local icon
|
||||
icon=$(get_icon_name "$deliverable")
|
||||
mkdir -p "$archive_dir"
|
||||
|
||||
# Generate docset.json
|
||||
local version
|
||||
version=$(cat "$build_dir/$deliverable-version.txt")
|
||||
sed "s/VERSION/$version/" "$files_dir/docset-$deliverable.json" > "$archive_dir/docset.json"
|
||||
# Generated tgz archive
|
124
scripts/create-pr.sh
Executable file
124
scripts/create-pr.sh
Executable file
@ -0,0 +1,124 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
if ! git config --global user.name ;then
|
||||
# If no global git configs exist, let's set some temporary values
|
||||
export GIT_COMMITTER_NAME="${GIT_COMMITTER_NAME:-"ViViDboarder"}"
|
||||
export GIT_COMMITTER_EMAIL="${GIT_COMMITTER_EMAIL:-"ViViDboarder@gmail.com"}"
|
||||
export GIT_AUTHOR_NAME="$GIT_COMMITTER_NAME"
|
||||
export GIT_AUTHOR_EMAIL="$GIT_COMMITTER_EMAIL"
|
||||
fi
|
||||
# Get name of the fork and target repo
|
||||
FORK_REPO="${FORK_REPO:-"ViViDboarder/Dash-User-Contributions"}"
|
||||
TARGET_REPO="${TARGET_REPO:-"ViViDboarder/Dash-User-Contributions"}"
|
||||
|
||||
# If no github user is provided, take it from the fork name
|
||||
if [ -z "${GITHUB_USER:-""}" ]; then
|
||||
GITHUB_USER="${FORK_REPO%%/*}"
|
||||
fi
|
||||
GITHUB_TOKEN="${GITHUB_TOKEN:-default}"
|
||||
|
||||
WORKDIR=$(pwd)
|
||||
TMP_DIR="$WORKDIR/repotmp"
|
||||
REPO_DIR="$TMP_DIR/Dash-User-Contributions"
|
||||
|
||||
function validate() {
|
||||
if [ -z "$GITHUB_TOKEN" ]; then
|
||||
echo "Must provide \$GITHUB_TOKEN as an environment variable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Creating PR for $GITHUB_USER to $TARGET_REPO"
|
||||
}
|
||||
|
||||
function read_version() {
|
||||
local apex_version
|
||||
apex_version="$(cat ./build/apexcode-version.txt)"
|
||||
local pages_version
|
||||
pages_version="$(cat ./build/pages-version.txt)"
|
||||
local lightning_version
|
||||
lightning_version="$(cat ./build/lightning-version.txt)"
|
||||
|
||||
if [ "$apex_version" != "$pages_version" ] || [ "$apex_version" != "$lightning_version" ]; then
|
||||
echo "Apex: $apex_version, Pages: $pages_version, Lightning: $lightning_version"
|
||||
echo "One of the doc versions doesn't match"
|
||||
exit 1
|
||||
fi
|
||||
# All versions match, return one of them
|
||||
echo "$apex_version"
|
||||
}
|
||||
|
||||
function workdir_git() {
|
||||
cd "$REPO_DIR"
|
||||
if ! git "$@" ;then
|
||||
# Be sure to return to workdir after a failed git command
|
||||
cd "$WORKDIR"
|
||||
return 1
|
||||
fi
|
||||
cd "$WORKDIR"
|
||||
}
|
||||
|
||||
function shallow_clone_or_pull() {
|
||||
mkdir -p "$TMP_DIR"
|
||||
if [ -d "$REPO_DIR" ]; then
|
||||
workdir_git checkout master
|
||||
workdir_git pull --ff-only origin master
|
||||
else
|
||||
git clone --depth 1 "https://$GITHUB_USER:$GITHUB_TOKEN@github.com/$FORK_REPO" "$REPO_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
function copy_release() {
|
||||
cp -r archive/* "$REPO_DIR/docsets/"
|
||||
}
|
||||
|
||||
function create_release_branch() {
|
||||
local branch="$1"
|
||||
if ! workdir_git checkout -b "$branch" ; then
|
||||
echo "Could not create release branch. Release likely already exists."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function create_pr() {
|
||||
local version="$1"
|
||||
local branch="$2"
|
||||
local title="Update Salesforce docsets to $version"
|
||||
workdir_git checkout "$branch"
|
||||
workdir_git add .
|
||||
workdir_git commit -m "$title"
|
||||
workdir_git push origin HEAD
|
||||
local result
|
||||
result=$(curl \
|
||||
-u "$GITHUB_USER:$GITHUB_TOKEN" \
|
||||
-X POST \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
"https://api.github.com/repos/$TARGET_REPO/pulls" \
|
||||
-d "{\"title\":\"$title\",\"body\":\"This branch contains auto-generated updates to version $version\", \"head\":\"$GITHUB_USER:$branch\",\"base\":\"master\"}")
|
||||
|
||||
|
||||
local result_url
|
||||
if result_url="$(echo "$result" | jq --exit-status --raw-output .html_url)" ;then
|
||||
echo "Pull request created at $result_url"
|
||||
else
|
||||
echo "$result"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
validate
|
||||
|
||||
local version
|
||||
version="$(read_version)" || { echo "$version"; exit 1; }
|
||||
local branch="salesforce-$version"
|
||||
|
||||
shallow_clone_or_pull
|
||||
copy_release
|
||||
create_release_branch "$branch"
|
||||
create_pr "$version" "$branch"
|
||||
}
|
||||
|
||||
main
|
Loading…
Reference in New Issue
Block a user