-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): migrates circleci to github actions
- Loading branch information
Showing
2 changed files
with
185 additions
and
200 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
name: Build and Test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
container: | ||
image: openjdk:8-jdk | ||
env: | ||
_JAVA_OPTIONS: "-Xmx3G -Xms2G" | ||
defaults: | ||
run: | ||
working-directory: . | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup System Tools | ||
run: | | ||
apt update -y | ||
apt install -y gnupg2 curl | ||
- name: Install Node.js | ||
run: | | ||
curl -fsSL https://deb.nodesource.com/setup_16.x | bash - | ||
apt-get install -y nodejs | ||
- name: Check Node.js version | ||
run: node --version | ||
- name: Verify files | ||
run: | | ||
curl -sSL https://secchannel.rsk.co/SUPPORT.asc | gpg2 --import - | ||
gpg2 --verify SHA256SUMS.asc && sha256sum --check SHA256SUMS.asc | ||
- name: List Files in gradle Directory | ||
run: ls -al gradle && ls -al gradle/wrapper | ||
|
||
- uses: actions/cache@v4 | ||
name: Cache Gradle | ||
with: | ||
path: | | ||
.gradle/caches | ||
gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Build | ||
run: | | ||
./configure.sh | ||
./gradlew --no-daemon dependencies | ||
./gradlew --no-daemon --stacktrace build -x test | ||
ls -la ./gradle/wrapper/gradle-wrapper.jar | ||
tests: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
container: | ||
image: openjdk:8-jdk | ||
defaults: | ||
run: | ||
working-directory: . | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup System Tools | ||
run: | | ||
apt update -y | ||
apt install -y curl | ||
- name: Install Node.js | ||
run: | | ||
curl -fsSL https://deb.nodesource.com/setup_16.x | bash - | ||
apt-get install -y nodejs | ||
- name: Check Node.js version | ||
run: node --version | ||
|
||
- uses: actions/cache@v4 | ||
name: Restore gradle cache | ||
with: | ||
path: | | ||
.gradle/caches | ||
gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Check Working Directory | ||
run: pwd | ||
- name: List Files in Current Directory | ||
run: ls -al | ||
- name: List Files in gradle Directory | ||
run: ls -al gradle && ls -al gradle/wrapper | ||
|
||
- name: Get Gradle jar | ||
run: | | ||
./configure.sh | ||
- name: Unit tests | ||
run: | | ||
chmod +x ./gradlew | ||
./gradlew --no-daemon --stacktrace test | ||
- name: Integration tests | ||
run: | | ||
chmod +x ./gradlew | ||
./gradlew --no-daemon --stacktrace test | ||
- name: Save test results | ||
run: | | ||
mkdir -p ~/junit/ | ||
find rskj-core/build/test-results -type f -name "*.xml" -exec cp {} ~/junit/ \; | ||
if: always() | ||
|
||
mining-tests: | ||
needs: tests | ||
runs-on: ubuntu-latest | ||
container: | ||
image: alpine:3.10 | ||
defaults: | ||
run: | ||
working-directory: . | ||
steps: | ||
- name: Setup System Tools | ||
run: | | ||
apt update -y | ||
apt install -y curl jq | ||
- name: Get Gradle jar | ||
run: | | ||
./configure.sh | ||
- name: Mining integration tests | ||
run: | | ||
wait_for_completion() { | ||
# inspired from https://discuss.circleci.com/t/waiting-for-build-to-complete-when-invoked-via-http-api/14989 | ||
build_number=$1 | ||
poll_interval=60 | ||
i=0 | ||
max_count=20 | ||
while [ $i -lt $max_count ]; do | ||
# output to avoid CircleCI considering the job stuck | ||
res=$(curl -Ssfu "$CIRCLE_INTEGRATIONS_TOKENS:" \ | ||
"https://circleci.com/api/v1.1/project/github/$MIT_ORGANIZATION/$MIT_PROJECT/$build_number" \ | ||
| jq -r '[.lifecycle, .outcome] | @tsv') | ||
IFS=" " set -- $res | ||
lifecycle=${1:-} | ||
outcome=${2:-} | ||
if [ "$lifecycle" = "queued" ]; then | ||
printf "Build is enqueued. Waiting...\n" | ||
# don't increment $i | ||
else | ||
printf "[%02u/%02u] Waiting for build %s ...\n" \ | ||
"$i" "$max_count" "$build_url" | ||
i=$(($i + 1)) | ||
fi | ||
if [ "$lifecycle" = "finished" ]; then | ||
printf "Build %u finished. Outcome: \"%s\".\n" \ | ||
"$build_number" "$outcome" | ||
# return success iff job outcome is "success" | ||
test "$outcome" = "success" | ||
return $? | ||
fi | ||
|
||
sleep $poll_interval | ||
done | ||
return 1 | ||
} | ||
|
||
json_payload='{ | ||
"build_parameters": { | ||
"RSKJ_CIRCLE_BRANCH": "'$CIRCLE_BRANCH'", | ||
"RSKJ_CIRCLE_USERNAME": "'$CIRCLE_PROJECT_USERNAME'", | ||
"RSKJ_CIRCLE_REPONAME": "'$CIRCLE_PROJECT_REPONAME'", | ||
"RSKJ_PR_NUMBER": "'$CIRCLE_PR_NUMBER'", | ||
"RSKJ_CIRCLE_SHA1": "'$CIRCLE_SHA1'" | ||
} | ||
}' | ||
res=$(curl -Ssf -u "$CIRCLE_INTEGRATIONS_TOKEN:" \ | ||
-H "Content-type: application/json" -d "$json_payload" \ | ||
"https://circleci.com/api/v1.1/project/github/$MIT_ORGANIZATION/$MIT_PROJECT/tree/$MIT_BRANCH" \ | ||
| jq -r '[.build_url, .build_num] | @tsv') | ||
IFS=" " set -- $res | ||
test $# -eq 2 # ensure exactly 2 values are expanded | ||
build_url=$1 | ||
build_num=$2 | ||
printf "Running mining integration tests. Follow it on:\n\n %s\n\n" "$build_url" | ||
sleep 10 # give CircleCI some time to spin up the job | ||
wait_for_completion "$build_num" |