Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci migration to Github Actions, part 3 #5978

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 84 additions & 24 deletions .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,70 @@ on:
branches: [master]
tags:

# Mage's `GenerateEnvFile` talks to GH API to setup tags, versions, etc.
env:
GITHUB_OWNER: mysteriumnetwork
GITHUB_REPO: node
GITHUB_SNAPSHOT_REPO: node-builds
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
setup-env:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Prepare environment
run: |
RELEASE_BUILD=false
if [[ "${GITHUB_REF}" == /refs/tags/* ]]; then RELEASE_BUILD=true; fi

RC_BUILD=false
if [[ "${GITHUB_REF}" == /refs/tags/*-rc ]]; then RC_BUILD=true; fi

SNAPSHOT_BUILD=false
if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then SNAPSHOT_BUILD=true; fi

PR_BUILD=false
if [[ "${SNAPSHOT_BUILD}" == "false" && "${RELEASE_BUILD}" == "false" ]]; then PR_BUILD=true; fi

BUILD_NUMBER="${{ github.run_id }}"-ghactions

if [[ "${RELEASE_BUILD}" == "true" ]]; then
BUILD_VERSION="${GITHUB_REF#/refs/tags/}";
elif [[ "${SNAPSHOT_BUILD}" == "true" ]]; then
BUILD_VERSION="$(git describe --abbrev=0 --tags)"-1snapshot-"$(date '+%Y%m%dT%H%M')"-"$(echo ${GITHUB_SHA} | cut -c1-8)";
elif [[ "${PR_BUILD}" == "true" ]]; then
BRANCH="${GITHUB_HEAD_REF////-}"
if [[ "${BRANCH}" == "" ]]; then BRANCH="${GITHUB_REF_NAME}"; fi
BUILD_VERSION="$(git describe --abbrev=0 --tags)"-1branch-"${BRANCH}";
fi

cat <<EOT >> env.sh
export RELEASE_BUILD=$RELEASE_BUILD;
export RC_BUILD=$RC_BUILD;
export PR_BUILD=$PR_BUILD;
export SNAPSHOT_BUILD=$SNAPSHOT_BUILD;
export BUILD_NUMBER=$BUILD_NUMBER;
export BUILD_VERSION=$BUILD_VERSION;
EOT

- uses: actions/upload-artifact@v4
with:
name: env.sh
path: env.sh

build-packages:
runs-on: ubuntu-latest
needs: [setup-env]

strategy:
max-parallel: 4
max-parallel: 6
matrix:
platform:
- PackageLinuxRaspberryImage
Expand All @@ -36,40 +87,47 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Generate Env
run: go run mage.go -v GenerateEnvFile
- uses: actions/download-artifact@v4
with:
name: env.sh

- name: Create bucket
if: |
github.ref == 'refs/heads/master' ||
github.ref_type == 'tag'
env:
AWS_EC2_METADATA_DISABLED: true
run: |
source env.sh
go run mage.go -v MakeBucket

- name: Setup FPM
run: |
sudo apt-get install ruby-dev build-essential
sudo gem i fpm -f

- name: Build package
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
source build/env.sh
# Following line ensures that s3 bucket name won't overlap with the old CI's target
# Should be removed when the old CI is disabled
export BUILD_NUMBER=$BUILD_NUMBER"-ghactions"
go run mage.go -v ${{ matrix.platform }}
source env.sh
unset CI # workaround for "PackageAndroid" target
sudo -E go run mage.go -v ${{ matrix.platform }}

build-swagger:
runs-on: ubuntu-latest
needs: [build-packages]
needs: [setup-env, build-packages]

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: Generate Env
run: go run mage.go -v GenerateEnvFile
- uses: actions/download-artifact@v4
with:
name: env.sh
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
Expand All @@ -79,12 +137,14 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Build docker
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
source build/env.sh
# Following line ensures that s3 bucket name won't overlap with the old CI's target
# Should be removed when the old CI is disabled
export BUILD_NUMBER=$BUILD_NUMBER"-ghactions"
source env.sh
go run mage.go -v PackageDockerSwaggerRedoc

release:
needs: [build-packages, build-swagger]
uses: ./.github/workflows/release.yml
secrets: inherit
if: |
github.ref == 'refs/heads/master' ||
github.ref_type == 'tag'
110 changes: 110 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Release
on:
workflow_call:

env:
GITHUB_OWNER: mysteriumnetwork
GITHUB_REPO: node
GITHUB_SNAPSHOT_REPO: node-builds
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

jobs:
release-snapshot:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'

strategy:
max-parallel: 3
matrix:
platform:
- ReleaseGithubSnapshot
# Nightly build
# - ReleaseGithubNightly
- ReleaseDockerSnapshot
- ReleaseDebianPPASnapshot

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- uses: actions/download-artifact@v4
with:
name: env.sh
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Release snapshot
run: |
source env.sh
sudo -E go run mage.go -v ${{ matrix.platform }}

- name: Release Go report
if: github.ref == 'refs/heads/master'
run: bin/release_goreport

release-tag:
runs-on: ubuntu-latest
if: github.ref_type == 'tag'

strategy:
max-parallel: 4
matrix:
platform:
- ReleaseGithubTag
- ReleaseDockerTag
- ReleaseDebianPPAPreRelease
- ReleaseAndroidSDK
- ReleaseAndroidProviderSDK

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- uses: actions/download-artifact@v4
with:
name: env.sh
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Release tag
run: |
source build/env.sh
sudo -E go run mage.go -v ${{ matrix.platform }}

post-release:
runs-on: ubuntu-latest
needs: [release-snapshot, release-tag]
if: always() && contains(join(needs.*.result, ','), 'success')

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- uses: actions/download-artifact@v4
with:
name: env.sh
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Remove bucket
env:
AWS_EC2_METADATA_DISABLED: true
run: |
source env.sh
go run mage.go -v RemoveBucket
# - name: Notify UptimeRobot
# if: github.ref == 'refs/heads/master'
# run: |
# if [ "$NIGHTLY_BUILD" = "1" -o "$NIGHTLY_BUILD" = "T" -o "$NIGHTLY_BUILD" = "true" -o "$NIGHTLY_BUILD" = "True" -o "$NIGHTLY_BUILD" = "TRUE" ]; then
# curl -so /dev/null -I "$NIGHTLY_UPTIMEROBOT"
# fi
# - name: PR Avado
# run: |
# source env.sh
# go run mage.go -v CreateAvadoPR

27 changes: 21 additions & 6 deletions .github/workflows/tests-and-linters.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Tests
on:
on:
pull_request:

env:
Expand All @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.21.x'

Expand All @@ -31,14 +31,13 @@ jobs:
file: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}

e2e-tests:
e2e-basic:
runs-on: ubuntu-latest
needs: unit-tests

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.21.x'

Expand All @@ -51,10 +50,26 @@ jobs:
- name: E2E basic test
run: go run mage.go -v TestE2EBasic

e2e-nat:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: E2E NAT test
run: go run mage.go -v TestE2ENAT

verify-build:
needs: [unit-tests, e2e-tests]
needs: [unit-tests, e2e-basic, e2e-nat]
uses: ./.github/workflows/build-packages.yml
secrets: inherit