Migrate CI to actions, build artifacts (#89)

* Create go workflow

* Delete travis config

* Update build script

* Create apple workflow

* Create android workflow

Co-authored-by: marin thiercelin <marin.thiercelin@pm.me>
This commit is contained in:
wussler 2020-10-19 10:07:25 +02:00 committed by GitHub
parent d53bd4a351
commit 6b2ac0b11c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 263 additions and 123 deletions

33
.github/workflows/android.yml vendored Normal file
View file

@ -0,0 +1,33 @@
name: Gomobile for Android
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
name: Build library for Android with gomobile
runs-on: ubuntu-latest
steps:
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: |
./build.sh android
find build
- name: Upload Android artifacts
uses: actions/upload-artifact@v2
with:
name: Android build
path: build/android
if-no-files-found: error

38
.github/workflows/go.yml vendored Normal file
View file

@ -0,0 +1,38 @@
name: Go test and lint
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
go install github.com/golangci/golangci-lint/cmd/golangci-lint
- name: Test
run: go test -v -race ./...
- name: Lint
run: golangci-lint run ./...

70
.github/workflows/ios.yml vendored Normal file
View file

@ -0,0 +1,70 @@
name: Gomobile for iOS
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
name: Build library for iOS with gomobile
runs-on: macos-latest
steps:
- name: Set up xcode 12.2
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 12.2
id: xcode
- name: Set up Go 1.15
uses: actions/setup-go@v2
with:
go-version: ^1.15
id: go
- name: Checkout
uses: actions/checkout@v2
- name: Build
env:
platform: ${{ 'iOS Simulator' }}
run: |
./build.sh apple
find build
- name: Upload iOS artifacts
uses: actions/upload-artifact@v2
with:
name: iOS build
path: build/ios
if-no-files-found: error
- name: Upload mac OS artifacts
uses: actions/upload-artifact@v2
with:
name: mac OS build
path: build/macos
if-no-files-found: error
- name: Upload mac OS ui artifacts
uses: actions/upload-artifact@v2
with:
name: mac OS ui build
path: build/macos-ui
if-no-files-found: error
- name: Upload iOS simulator artifacts
uses: actions/upload-artifact@v2
with:
name: iOS simulator build
path: build/ios-simulator
if-no-files-found: error
- name: Upload xcframework
uses: actions/upload-artifact@v2
with:
name: Gopenpgp xcframework
path: build/Gopenpgp.xcframework
if-no-files-found: error

View file

@ -1,42 +0,0 @@
# use the latest ubuntu environment (18.04) available on travis
dist: bionic
language: go
# Force-enable Go modules. Also force go to use the code in vendor/
# These will both be unnecessary when Go 1.14 lands.
env: GO111MODULE=on
go:
- 1.12.x
- 1.13.x
- 1.14.x
# Only clone the most recent commit.
git:
depth: 1
# Skip the install step. Don't `go get` dependencies. Only build with the code
# in vendor/
install: true
# Don't email me the results of the test runs.
notifications:
email: false
# Anything in before_script that returns a nonzero exit code will flunk the
# build and immediately stop. It's sorta like having set -e enabled in bash.
# Make sure you've pinned the version of golangci-lint by running this command
# in your project directory:
# GO111MODULE=on go get github.com/golangci/golangci-lint@v1.21.0
# You should see this line in your go.mod file:
# github.com/golangci/golangci-lint v1.21.0
before_script:
- go install github.com/golangci/golangci-lint/cmd/golangci-lint
# script always runs to completion (set +e). If we have linter issues AND a
# failing test, we want to see both. Configure golangci-lint with a
# .golangci.yml file at the top level of your repo.
script:
- golangci-lint run # run a bunch of code checkers/linters in parallel
- go test -v -race ./... # Run all the tests with the race detector enabled

177
build.sh
View file

@ -1,101 +1,120 @@
#!/bin/bash
PACKAGE_PATH="github.com/ProtonMail/gopenpgp"
cd "${GOPATH}"/src/${PACKAGE_PATH} || exit
if ! [ -L "v2" ]; then
ln -s . v2
fi
printf "\e[0;32mStart installing vendor \033[0m\n\n"
export GO111MODULE=on
go mod vendor
printf "\e[0;32mDone \033[0m\n\n"
OUTPUT_PATH="dist"
ANDROID_OUT=${OUTPUT_PATH}/"Android"
ANDROID_OUT_FILE_NAME="gopenpgp"
ANDROID_OUT_FILE=${ANDROID_OUT}/${ANDROID_OUT_FILE_NAME}.aar
ANDROID_JAVA_PAG="com.proton.${ANDROID_OUT_FILE_NAME}"
IOS_OUT=${OUTPUT_PATH}/"iOS"
IOS_OUT_FILE_NAME="Crypto"
IOS_OUT_FILE=${IOS_OUT}/${IOS_OUT_FILE_NAME}.framework
mkdir -p $ANDROID_OUT
mkdir -p $IOS_OUT
install()
install_modules()
{
INSTALL_NAME=$1
FROM_PATH=$2
INSTALL_PATH=$3
if [[ -z "${INSTALL_PATH}" ]]; then
printf "\e[0;32m ${INSTALL_NAME} project path is undefined! ignore this !\033[0m\n";
else
printf "\n\e[0;32mDo you wise to install the library into ${INSTALL_NAME} project \033[0m\n"
printf "\e[0;37m${INSTALL_NAME} Project Path: \033[0m"
printf "\e[0;37m${INSTALL_PATH} \033[0m"
printf "\n"
while true; do
read -p "[Yy] or [Nn]:" yn
case $yn in
[Yy]* )
printf "\e[0;32m Installing .... \033[0m\n";
cp -rf ${FROM_PATH} ${INSTALL_PATH}/
printf "\n\e[0;32mInstalled \033[0m\n\n"
break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
printf "\e[0;32mStart installing go modules and their dependencies \033[0m\n\n"
GO111MODULE=on
go mod download
printf "\e[0;32mDone \033[0m\n\n"
}
install_gomobile()
{
printf "\e[0;32mInstalling gomobile fork\033[0m\n\n"
go build golang.org/x/mobile/cmd/gomobile
go build golang.org/x/mobile/cmd/gobind
printf "\e[0;32mDone \033[0m\n\n"
PATH=$(pwd):$PATH
}
# import function, add internal package in the build
import()
{
PACKAGES=" ${PACKAGES} ${PACKAGE_PATH}/v2/$1"
}
external()
{
PACKAGES="${PACKAGES} $1"
}
######## MARK -- Main
build()
{
TARGET=$1
if [ $TARGET = "android" ]; then
OUT_EXTENSION="aar"
else
OUT_EXTENSION="framework"
fi
TARGET_DIR=${BUILD_DIR}/${TARGET}
TARGET_OUT_FILE=${TARGET_DIR}/${BUILD_NAME}.${OUT_EXTENSION}
mkdir -p $TARGET_DIR
printf "\e[0;32mStart Building ${TARGET} .. Location: ${TARGET_DIR} \033[0m\n\n"
gomobile bind -tags mobile -target $TARGET -x -o ${TARGET_OUT_FILE} -ldflags="${LDFLAGS}" ${PACKAGES}
}
#flags
DFLAGS="-s -w"
## ======== Config ===============
# ==== Generic parameters ======
# output directory
BUILD_DIR="./build"
# linkage flags
LDFLAGS="'all=-s -w'"
# name of the build output
BUILD_NAME="Gopenpgp"
# ==== Packages to include =====
PACKAGES=""
#add internal package
## crypto must be the first one, and the framework name better same with the first package name
import crypto
import armor
import constants
import models
import subtle
import helper
import github.com/ProtonMail/gopenpgp/v2/crypto
import github.com/ProtonMail/gopenpgp/v2/armor
import github.com/ProtonMail/gopenpgp/v2/constants
import github.com/ProtonMail/gopenpgp/v2/models
import github.com/ProtonMail/gopenpgp/v2/subtle
import github.com/ProtonMail/gopenpgp/v2/helper
## add external package
if [ "$1" != '' ]; then
external $1
fi
######## ======== Main ===========
printf "PACKAGES: ${PACKAGES}\n"
# We get the needed go modules stated in the go.mod file
install_modules
install_gomobile
go env
echo "gomobile: $(which gomobile)"
echo "gobind: $(which gobind)"
printf "Packages included : ${PACKAGES}\n"
## start building
# ================= Apple Builds ======================
if [ "$#" -ne 1 ] || [ $1 = apple ]; then
# ========== iOS and Simulator =========
printf "\e[0;32mStart Building iOS framework .. Location: ${IOS_OUT} \033[0m\n\n"
gomobile bind -target ios -o ${IOS_OUT_FILE} -ldflags="${DFLAGS}" ${PACKAGES}
# install iOS ${IOS_OUT_FILE} ${IOS_PROJECT_PATH}
# we build the framework for the ios devices
build ios
printf "\e[0;32mStart Building Android lib .. Location: ${ANDROID_OUT} \033[0m\n\n"
gomobile bind -target android -javapkg ${ANDROID_JAVA_PAG} -o ${ANDROID_OUT_FILE} -ldflags="${DFLAGS}" ${PACKAGES}
# install Android ${ANDROID_OUT} ${ANDROID_PROJECT_PATH}
# we make a copy of the framework for the simulator
IOSSIM_OUT=${BUILD_DIR}/"ios-simulator"
mkdir -p $IOSSIM_OUT
IOS_OUT_FILE=${BUILD_DIR}/ios/${BUILD_NAME}.framework
IOSSIM_OUT_FILE=${IOSSIM_OUT}/${BUILD_NAME}.framework
printf "\e[0;32mInstalling frameworks. \033[0m\n\n"
cp -R $IOS_OUT_FILE $IOSSIM_OUT_FILE;
printf "\e[0;32mAll Done. \033[0m\n\n"
# we remove the unwanted archs for ios and simulator
lipo $IOSSIM_OUT_FILE/Versions/A/${BUILD_NAME} -remove arm64 -output $IOSSIM_OUT_FILE/Versions/A/${BUILD_NAME};
lipo $IOS_OUT_FILE/Versions/A/${BUILD_NAME} -remove x86_64 -output $IOS_OUT_FILE/Versions/A/${BUILD_NAME};
# ========== macOs ====================
# we build the framework for the macos devices
build macos
# ======== macOSUI ===============
# we build the framework for the macos-ui target
build macos-ui
# we join all platform's framework in a xcframework
XCFRAMEWORK_OUT_FILE=$BUILD_DIR/$BUILD_NAME.xcframework
xcodebuild -create-xcframework -framework $BUILD_DIR/ios/$BUILD_NAME.framework -framework $BUILD_DIR/macos/$BUILD_NAME.framework -framework $BUILD_DIR/macos-ui/$BUILD_NAME.framework -framework $BUILD_DIR/ios-simulator/$BUILD_NAME.framework -output $XCFRAMEWORK_OUT_FILE
fi
# ================ Android Build =====================
if [ "$#" -ne 1 ] || [ $1 = android ]; then
ANDROID_JAVA_PAG="com.proton.${ANDROID_OUT_FILE_NAME}"
build android
printf "\e[0;32mAll Done. \033[0m\n\n"
fi

7
go.mod
View file

@ -1,12 +1,15 @@
module github.com/ProtonMail/gopenpgp/v2
go 1.12
go 1.15
require (
github.com/ProtonMail/go-mime v0.0.0-20190923161245-9b5a4261663a
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.4.0
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/mobile v0.0.0-20200801112145-973feb4309de
)
replace golang.org/x/crypto => github.com/ProtonMail/crypto v0.0.0-20200416114516-1fa7f403fb9c
replace golang.org/x/mobile => github.com/zhj4478/mobile v0.0.0-20201014085805-7a2d68bf792f

19
go.sum
View file

@ -1,3 +1,4 @@
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ProtonMail/crypto v0.0.0-20200416114516-1fa7f403fb9c h1:DAvlgde2Stu18slmjwikiMPs/CKPV35wSvmJS34z0FU=
github.com/ProtonMail/crypto v0.0.0-20200416114516-1fa7f403fb9c/go.mod h1:Pxr7w4gA2ikI4sWyYwEffm+oew1WAJHzG1SiDpQMkrI=
github.com/ProtonMail/go-mime v0.0.0-20190923161245-9b5a4261663a h1:W6RrgN/sTxg1msqzFFb+G80MFmpjMw61IU+slm+wln4=
@ -18,7 +19,19 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/zhj4478/mobile v0.0.0-20201014085805-7a2d68bf792f h1:3NX1KS08WQ2sF4EYpqlpWlBDpxpcaIkhywFAKQM1iYQ=
github.com/zhj4478/mobile v0.0.0-20201014085805-7a2d68bf792f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -26,6 +39,12 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69 h1:yBHHx+XZqXJBm6Exke3N7V9gnlsyXxoCPEb1yVenjfk=
golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=