Add necessary files for GitHub Action
This commit is contained in:
144
.ci.sh
Normal file
144
.ci.sh
Normal file
@@ -0,0 +1,144 @@
|
||||
#!/bin/sh
|
||||
|
||||
PATH=$PATH:"$(go env GOPATH)/bin"
|
||||
GO111MODULE=on
|
||||
ASC_URL=https://keybase.io/nirui/pgp_keys.asc
|
||||
PACKAGE=github.com/niruix/sshwifty
|
||||
VERSION_VARIABLE=github.com/niruix/sshwifty/application.version
|
||||
BUILD_TARGETS="darwin/amd64 windows/386 windows/amd64 openbsd/386 openbsd/amd64 openbsd/arm openbsd/arm64 freebsd/386 freebsd/amd64 freebsd/arm freebsd/arm64 linux/386 linux/amd64 linux/arm linux/arm64 linux/riscv64 linux/ppc64 linux/ppc64le linux/mips linux/mipsle linux/mips64 linux/mips64le"
|
||||
|
||||
DOCKER_BUILD_TARGETS="linux/amd64,linux/arm/v7,linux/arm64"
|
||||
DOCKER_CLI_EXPERIMENTAL=enabled
|
||||
|
||||
SSHWIFTY_VERSION=$(git describe --always --dirty='*' --tag)
|
||||
SSHWIFTY_COMMIT=$(git describe --always)
|
||||
SSHWIFTY_RELEASE=$([ "$(echo $SSHWIFTY_VERSION | grep -oP ^[0-9]+\.[0-9]+\.[0-9]+\-[a-zA-Z0-9]+\-release$)" = '' ] || echo 'yes')
|
||||
SSHWIFTY_DEPLOY=$([ "$SSHWIFTY_RELEASE" != 'yes' ] || echo 'yes')
|
||||
SSHWIFTY_TEST_COVER=$([ "$COVERALLS_TOKEN" = '' ] || echo 'yes')
|
||||
SSHWIFTY_DOCKER_IMAGE_TAG="$DOCKER_HUB_USER/github_action_test"
|
||||
SSHWIFTY_DOCKER_IMAGE_PUSH_TAG="$SSHWIFTY_DOCKER_IMAGE_TAG:$SSHWIFTY_VERSION"
|
||||
SSHWIFTY_DOCKER_IMAGE_PUSH_TAG_LATEST="$SSHWIFTY_DOCKER_IMAGE_TAG:latest"
|
||||
|
||||
child() {
|
||||
cpid=""
|
||||
ret=0
|
||||
i=0
|
||||
|
||||
echo "+ Spawning $# childs ..."
|
||||
|
||||
for c in "$@"; do
|
||||
( (((((eval "$c"; echo $? >&3) | sed "s/^/\|------ ($i) /" >&4) 2>&1 | sed "s/^/\|------ ($i)!/" >&2) 3>&1) | (read xs; exit $xs)) 4>&1) & ppid=$!
|
||||
|
||||
cpid="$cpid $ppid"
|
||||
|
||||
echo "+ Child $i (PID $ppid): $c ..."
|
||||
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
for c in $cpid; do
|
||||
wait $c
|
||||
|
||||
cret=$?
|
||||
[ $cret -eq 0 ] && continue
|
||||
|
||||
echo "* Child PID $c has failed." >&2
|
||||
|
||||
ret=$cret
|
||||
done
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
retry() {
|
||||
res=0
|
||||
|
||||
for i in $(seq 0 36); do
|
||||
$@
|
||||
res=$?
|
||||
|
||||
[ $res -eq 0 ] && return $res || sleep 10
|
||||
done
|
||||
|
||||
return $res
|
||||
}
|
||||
|
||||
catch() {
|
||||
(eval '"$@"')
|
||||
res=$?
|
||||
|
||||
[ $res -eq 0 ] && return $res
|
||||
|
||||
echo "Command \"$@\" has failed. Exit code: $res"
|
||||
|
||||
exit $res
|
||||
}
|
||||
|
||||
if [ "$SSHWIFTY_TEST_COVER" = 'yes' ]; then
|
||||
echo 'Downloading test cover reporter ...'
|
||||
|
||||
[ "$(which overalls)" != '' ] || catch retry go get -v github.com/go-playground/overalls
|
||||
[ "$(which goveralls)" != '' ] || catch retry go get -v github.com/mattn/goveralls
|
||||
fi
|
||||
|
||||
if [ "$SSHWIFTY_DEPLOY" = 'yes' ]; then
|
||||
echo 'Downloading compile & deploy tools ...'
|
||||
|
||||
[ "$(which ghr)" != '' ] || catch retry go get -v github.com/tcnksm/ghr
|
||||
[ "$(which gox)" != '' ] || catch retry go get -v github.com/mitchellh/gox
|
||||
|
||||
echo 'Fetching extra references from the repository ...'
|
||||
|
||||
catch retry git fetch --tags --depth 1
|
||||
fi
|
||||
|
||||
echo "Version: $SSHWIFTY_VERSION"
|
||||
echo "Files: $(pwd)" && ls -la
|
||||
export
|
||||
|
||||
catch retry npm install
|
||||
|
||||
catch npm run generate
|
||||
|
||||
catch go vet ./...
|
||||
catch npm run testonly
|
||||
|
||||
if [ "$SSHWIFTY_TEST_COVER" = 'yes' ]; then
|
||||
catch overalls -project="$PACKAGE" -covermode=count
|
||||
catch goveralls -coverprofile=./overalls.coverprofile -service github
|
||||
fi
|
||||
|
||||
if [ "$SSHWIFTY_DEPLOY" = 'yes' ]; then
|
||||
catch child \
|
||||
'
|
||||
docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_PASSWORD" &&
|
||||
docker buildx create --use --driver docker-container --name buildx-instance &&
|
||||
docker buildx build --tag "$SSHWIFTY_DOCKER_IMAGE_PUSH_TAG" --tag "$SSHWIFTY_DOCKER_IMAGE_PUSH_TAG_LATEST" --platform "$DOCKER_BUILD_TARGETS" --build-arg "$DOCKER_NPM_REGISTRY" --progress plain --push .
|
||||
' \
|
||||
'
|
||||
mkdir -p ./.tmp/generated ./.tmp/release &&
|
||||
curl "$ASC_URL" > ./.tmp/release/GPG.asc &&
|
||||
gpg --import ./.tmp/release/GPG.asc &&
|
||||
git archive --format tar --output ./.tmp/release/src HEAD &&
|
||||
CGO_ENABLED=0 gox -ldflags "-s -w -X $VERSION_VARIABLE=$SSHWIFTY_VERSION" -osarch "$BUILD_TARGETS" -output "./.tmp/release/{{.Dir}}_${SSHWIFTY_VERSION}_{{.OS}}_{{.Arch}}/{{.Dir}}_{{.OS}}_{{.Arch}}" &&
|
||||
echo "# Version $SSHWIFTY_VERSION" > ./.tmp/release/Note &&
|
||||
echo >> ./.tmp/release/Note &&
|
||||
echo "Updates introduced since $(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1))" >> ./.tmp/release/Note &&
|
||||
git log $(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1))..HEAD --pretty=format:"- %h %s - (%an) %GK %G?" >> ./.tmp/release/Note &&
|
||||
echo '"'"'#!/bin/sh'"'"' > ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'echo Preparing for $1 ... && \'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'(cd $1/ && find . -maxdepth 1 -type f ! -name "SUM.*" -exec sha512sum {} \; > SUM.sha512) && \'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'(cp -v ./*.md $1/) && \'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'(cp -v ./*.example.json $1/) && \'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'(cp -v ./.tmp/release/GPG.asc $1/) && \'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'(cp -v ./.tmp/release/Note $1/) && \'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'(cp -v ./.tmp/release/src $1/) && \'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
echo '"'"'(cd $1/ && tar zpcvf ../$(basename $(pwd)).tar.gz * --owner=0 --group=0)'"'"' >> ./.tmp/generated/prepare.sh &&
|
||||
chmod +x ./.tmp/generated/prepare.sh &&
|
||||
find ./.tmp/release/ -maxdepth 1 -type d ! -name "release" -exec ./.tmp/generated/prepare.sh {} \; &&
|
||||
find ./.tmp/release/ -maxdepth 1 -type d ! -name "release" -exec rm {} -rf \; &&
|
||||
find ./.tmp/release/ -maxdepth 1 -type f -name "*.tar.gz" -execdir sha512sum {} \; > ./.tmp/release/SUM.sha512 &&
|
||||
cat ./.tmp/release/SUM.sha512 &&
|
||||
ghr -t "$GITHUB_USER_TOKEN" -u "$GITHUB_USER" -n "$SSHWIFTY_VERSION-prebuild" -b "$(cat ./.tmp/release/Note)" -delete -prerelease "$SSHWIFTY_VERSION-prebuild" ./.tmp/release
|
||||
'
|
||||
fi
|
||||
33
.github/workflows/workflow.yml
vendored
Normal file
33
.github/workflows/workflow.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: Sshwifty-CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master, dev]
|
||||
tags: ["**-release"]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
CI:
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
steps:
|
||||
- name: Checking out source code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 50
|
||||
|
||||
- name: Run CI
|
||||
run: |
|
||||
export GITHUB_USER="${{ github.repository_owner }}"
|
||||
export GITHUB_USER_TOKEN="${{ secrets.GITHUB_TOKEN }}"
|
||||
export DOCKER_HUB_PASSWORD="${{ secrets.DOCKER_HUB_PASSWORD }}"
|
||||
export COVERALLS_TOKEN="${{ secrets.COVERALLS_TOKEN }}"
|
||||
export DOCKER_HUB_USER="${{ github.repository_owner }}"
|
||||
export DOCKER_NPM_REGISTRY="http://registry.npmjs.org/"
|
||||
|
||||
sudo apt-get update -qq -y
|
||||
sudo apt-get upgrade -qq -y
|
||||
sudo apt-get install -qq -y qemu qemu-user-static binfmt-support
|
||||
sudo systemctl restart docker
|
||||
|
||||
chmod +x ./.ci.sh && ./.ci.sh
|
||||
@@ -10,9 +10,10 @@ RUN set -ex && \
|
||||
(echo "Acquire::Retries \"8\";" >> /etc/apt/apt.conf) && \
|
||||
echo '#!/bin/sh' > /install.sh && echo 'apt-get update && apt-get install autoconf automake libtool build-essential ca-certificates curl git npm golang-go -y' >> /install.sh && chmod +x /install.sh && \
|
||||
/try.sh /install.sh && rm /install.sh && \
|
||||
/try.sh update-ca-certificates -f && c_rehash && \
|
||||
([ -z "$HTTP_PROXY" ] || (git config --global http.proxy "$HTTP_PROXY" && npm config set proxy "$HTTP_PROXY")) && \
|
||||
([ -z "$HTTPS_PROXY" ] || (git config --global https.proxy "$HTTPS_PROXY" && npm config set https-proxy "$HTTPS_PROXY")) && \
|
||||
/try.sh update-ca-certificates && \
|
||||
([ -z "$NPM_REGISTRY" ] || (npm config set registry="$NPM_REGISTRY")) && \
|
||||
export PATH=$PATH:"$(go env GOPATH)/bin" && \
|
||||
echo '#!/bin/sh' > /install.sh && echo "npm install -g npm || (npm cache clean -f && false)" >> /install.sh && chmod +x /install.sh && /try.sh /install.sh && rm /install.sh
|
||||
|
||||
@@ -22,6 +23,7 @@ COPY . /tmp/.build/sshwifty
|
||||
RUN set -ex && \
|
||||
cd / && \
|
||||
export PATH=$PATH:/ && \
|
||||
export CPPFLAGS='-DPNG_ARM_NEON_OPT=0' && \
|
||||
/try.sh apt-get install libpng-dev -y && \
|
||||
ls -l /tmp/.build/sshwifty && \
|
||||
/child.sh \
|
||||
|
||||
Reference in New Issue
Block a user