Skip to content

Commit

Permalink
Improve Azure Pipelines and build automation (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeuw authored Dec 5, 2020
1 parent 8c7c11f commit 37da5f6
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 90 deletions.
21 changes: 17 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ apply plugin: 'kotlin-android-extensions'


android {
signingConfigs {
}
compileSdkVersion 29
//buildToolsVersion '26.0.2'
ndkVersion "21.3.6528147"
defaultConfig {
applicationId "com.github.shadowsocks.plugin.ck_client"
minSdkVersion 21
Expand All @@ -24,7 +22,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "ck-client-${defaultConfig.versionName}.apk"
}
}
}

Expand All @@ -38,3 +39,15 @@ dependencies {
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

task printVersionName {
doLast {
println android.defaultConfig.versionName
}
}

task printNDKPath {
doLast {
println android.ndkDirectory
}
}
165 changes: 83 additions & 82 deletions app/src/make.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
#!/usr/bin/env bash

function getHostTag() {
# Copyright (C) 2010 The Android Open Source Project
# Modified by Andy Wang ([email protected])
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Detect host operating system and architecture
# The 64-bit / 32-bit distinction gets tricky on Linux and Darwin because
# uname -m returns the kernel's bit size, and it's possible to run with
# a 64-bit kernel and a 32-bit userland.
#
HOST_OS=$(uname -s)
case $HOST_OS in
Darwin) HOST_OS=darwin ;;
Linux) HOST_OS=linux ;;
FreeBsd) HOST_OS=freebsd ;;
CYGWIN* | *_NT-*) HOST_OS=windows ;;
*)
echo "ERROR: Unknown host operating system: $HOST_OS"
exit 1
;;
esac
echo "HOST_OS=$HOST_OS"

HOST_ARCH=$(uname -m)
case $HOST_ARCH in
i?86) HOST_ARCH=x86 ;;
x86_64 | amd64) HOST_ARCH=x86_64 ;;
*)
echo "ERROR: Unknown host CPU architecture: $HOST_ARCH"
exit 1
;;
esac
echo "HOST_ARCH=$HOST_ARCH"

# Detect 32-bit userland on 64-bit kernels
HOST_TAG="$HOST_OS-$HOST_ARCH"
case $HOST_TAG in
linux-x86_64 | darwin-x86_64)
# we look for x86_64 or x86-64 in the output of 'file' for our shell
# the -L flag is used to dereference symlinks, just in case.
file -L "$SHELL" | grep -q "x86[_-]64"
if [ $? != 0 ]; then
HOST_ARCH=x86
HOST_TAG=$HOST_OS-x86
echo "HOST_ARCH=$HOST_ARCH (32-bit userland detected)"
fi
;;
esac
# Check that we have 64-bit binaries on 64-bit system, otherwise fallback
# on 32-bit ones. This gives us more freedom in packaging the NDK.
if [ $HOST_ARCH = x86_64 -a ! -d $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG ]; then
HOST_TAG=$HOST_OS-x86
if [ $HOST_TAG = windows-x86 ]; then
HOST_TAG=windows
fi
echo "HOST_TAG=$HOST_TAG (no 64-bit prebuilt binaries detected)"
else
echo "HOST_TAG=$HOST_TAG"
fi
}

#Copyright (C) 2017 by Max Lv <[email protected]>
#Copyright (C) 2017 by Mygod Studio <[email protected]>
#This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Expand All @@ -10,81 +76,17 @@ function try() {
"$@" || exit -1
}

[ -z "$ANDROID_NDK_HOME" ] && ANDROID_NDK_HOME=ANDROID_SDK_ROOT/ndk-bundle

if [ ! -d "$ANDROID_NDK_HOME" ]; then
ANDROID_NDK_HOME=$USERPROFILE/AppData/Local/Android/Sdk/ndk-bundle
fi
pushd ../..
ANDROID_NDK_HOME="$(./gradlew -q printNDKPath)"
CK_RELEASE_TAG=v"$(./gradlew -q printVersionName)"
popd

while [ ! -d "$ANDROID_NDK_HOME" ]; do
echo "Path to ndk-bundle not found. Please enter the full path"
read -p '' ANDROID_NDK_HOME
done

# Copyright (C) 2010 The Android Open Source Project
# Modified by Andy Wang ([email protected])
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Detect host operating system and architecture
# The 64-bit / 32-bit distinction gets tricky on Linux and Darwin because
# uname -m returns the kernel's bit size, and it's possible to run with
# a 64-bit kernel and a 32-bit userland.
#
HOST_OS=$(uname -s)
case $HOST_OS in
Darwin) HOST_OS=darwin ;;
Linux) HOST_OS=linux ;;
FreeBsd) HOST_OS=freebsd ;;
CYGWIN* | *_NT-*) HOST_OS=windows ;;
*)
echo "ERROR: Unknown host operating system: $HOST_OS"
exit 1
;;
esac
echo "HOST_OS=$HOST_OS"

HOST_ARCH=$(uname -m)
case $HOST_ARCH in
i?86) HOST_ARCH=x86 ;;
x86_64 | amd64) HOST_ARCH=x86_64 ;;
*)
echo "ERROR: Unknown host CPU architecture: $HOST_ARCH"
exit 1
;;
esac
echo "HOST_ARCH=$HOST_ARCH"

# Detect 32-bit userland on 64-bit kernels
HOST_TAG="$HOST_OS-$HOST_ARCH"
case $HOST_TAG in
linux-x86_64 | darwin-x86_64)
# we look for x86_64 or x86-64 in the output of 'file' for our shell
# the -L flag is used to dereference symlinks, just in case.
file -L "$SHELL" | grep -q "x86[_-]64"
if [ $? != 0 ]; then
HOST_ARCH=x86
HOST_TAG=$HOST_OS-x86
echo "HOST_ARCH=$HOST_ARCH (32-bit userland detected)"
fi
;;
esac
# Check that we have 64-bit binaries on 64-bit system, otherwise fallback
# on 32-bit ones. This gives us more freedom in packaging the NDK.
if [ $HOST_ARCH = x86_64 -a ! -d $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG ]; then
HOST_TAG=$HOST_OS-x86
if [ $HOST_TAG = windows-x86 ]; then
HOST_TAG=windows
fi
echo "HOST_TAG=$HOST_TAG (no 64-bit prebuilt binaries detected)"
else
echo "HOST_TAG=$HOST_TAG"
fi

getHostTag
MIN_API=21
ANDROID_PREBUILT_TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG

Expand All @@ -99,38 +101,37 @@ ANDROID_X86_STRIP=$ANDROID_PREBUILT_TOOLCHAIN/bin/i686-linux-android-strip
ANDROID_X86_64_CC=$ANDROID_PREBUILT_TOOLCHAIN/bin/x86_64-linux-android${MIN_API}-clang
ANDROID_X86_64_STRIP=$ANDROID_PREBUILT_TOOLCHAIN/bin/x86_64-linux-android-strip

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEPS=$(pwd)/.deps
try mkdir -p $DEPS $DIR/main/jniLibs/armeabi-v7a $DIR/main/jniLibs/x86 $DIR/main/jniLibs/arm64-v8a $DIR/main/jniLibs/x86_64
try mkdir -p $DEPS $SRC_DIR/main/jniLibs/armeabi-v7a $SRC_DIR/main/jniLibs/x86 $SRC_DIR/main/jniLibs/arm64-v8a $SRC_DIR/main/jniLibs/x86_64

cd $DEPS || exit
try cd $DEPS
echo "Getting Cloak source code"
rm -rf Cloak
GO111MOD=on
git clone https://github.com/cbeuw/Cloak

cd Cloak || exit
go get -u
try git clone https://github.com/cbeuw/Cloak
cd Cloak
try git checkout tags/$CK_RELEASE_TAG
try go get -u ./...

cd cmd/ck-client || exit
cd cmd/ck-client

echo "Cross compiling ckclient for arm"
try env CGO_ENABLED=1 CC="$ANDROID_ARM_CC" GOOS=android GOARCH=arm GOARM=7 go build -ldflags="-s -w"
try mv ck-client $DIR/main/jniLibs/armeabi-v7a/libck-client.so
try mv ck-client $SRC_DIR/main/jniLibs/armeabi-v7a/libck-client.so

echo "Cross compiling ckclient for arm64"
try env CGO_ENABLED=1 CC="$ANDROID_ARM64_CC" GOOS=android GOARCH=arm64 go build -ldflags="-s -w"
try "$ANDROID_ARM64_STRIP" ck-client
try mv ck-client $DIR/main/jniLibs/arm64-v8a/libck-client.so
try mv ck-client $SRC_DIR/main/jniLibs/arm64-v8a/libck-client.so

echo "Cross compiling ckclient for x86"
try env CGO_ENABLED=1 CC="$ANDROID_X86_CC" GOOS=android GOARCH=386 go build -ldflags="-s -w"
try "$ANDROID_X86_STRIP" ck-client
try mv ck-client $DIR/main/jniLibs/x86/libck-client.so
try mv ck-client $SRC_DIR/main/jniLibs/x86/libck-client.so

echo "Cross compiling ckclient for x86_64"
try env CGO_ENABLED=1 CC="$ANDROID_X86_64_CC" GOOS=android GOARCH=amd64 go build -ldflags="-s -w"
try "$ANDROID_X86_64_STRIP" ck-client
try mv ck-client $DIR/main/jniLibs/x86_64/libck-client.so
try mv ck-client $SRC_DIR/main/jniLibs/x86_64/libck-client.so

echo "Success"
75 changes: 75 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Android
# Build your Android project with Gradle.
# Add steps that test, sign, and distribute the APK, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/android

trigger:
tags:
include:
- refs/tags/v*
branches:
exclude:
- "*"

pool:
vmImage: 'ubuntu-latest'

variables:
GOBIN: '$(GOPATH)/bin' # Go binaries path
GOROOT: '$(Agent.BuildDirectory)/go' # Go installation path
GOPATH: '$(Agent.BuildDirectory)/gopath' # Go workspace path

steps:
- script: |
mkdir -p '$(GOBIN)'
mkdir -p '$(GOPATH)/pkg'
mkdir -p '$(modulePath)'
shopt -s extglob
shopt -s dotglob
echo '##vso[task.prependpath]$(GOBIN)'
echo '##vso[task.prependpath]$(GOROOT)/bin'
wget "https://golang.org/dl/go1.15.2.linux-amd64.tar.gz" --output-document "$(Agent.BuildDirectory)/go1.15.2.tar.gz"
tar -C '$(Agent.BuildDirectory)' -xzf "$(Agent.BuildDirectory)/go1.15.2.tar.gz"
displayName: 'Set up the Go workspace'

- script: |
chmod +x ./gradlew
pushd '$(Build.SourcesDirectory)/app/src'
chmod +x ./make.sh
./make.sh
popd
displayName: 'Cross compiling ck-client binaries'
continueOnError: false

- task: Gradle@2
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'assembleRelease'

- task: AndroidSigning@2
inputs:
apkFiles: '**/*.apk'
jarsign: true
jarsignerKeystoreFile: 'mainAPK.jks'
jarsignerKeystorePassword: '$(jarsignerKeystorePassword)'
jarsignerKeystoreAlias: 'main'
jarsignerKeyPassword: '$(jarsignerKeyPassword)'
zipalign: true

- task: CopyFiles@2
inputs:
contents: '**/*.apk'
targetFolder: '$(build.artifactStagingDirectory)'

- task: GitHubRelease@0
inputs:
gitHubConnection: github.com_cbeuw
repositoryName: '$(Build.Repository.Name)'
action: 'create' # Options: create, edit, delete
target: '$(Build.SourceVersion)' # Required when action == Create || Action == Edit
tagSource: 'auto' # Required when action == Create# Options: auto, manual
addChangeLog: false # Optional
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue May 26 15:42:25 GMT+02:00 2020
#Sat Dec 05 00:29:38 GMT 2020
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

0 comments on commit 37da5f6

Please sign in to comment.