Skip to content

Commit

Permalink
add pr build workflow (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyTrivail committed Nov 5, 2020
1 parent 926ab60 commit 8719306
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ on:
repository_dispatch:
types: [dependency-build]

pull_request:
branches: [ main ]

env:
IMAGE_NAME: aws-otel-collector
PACKAGING_ROOT: build/packages
Expand Down
171 changes: 171 additions & 0 deletions .github/workflows/PR-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.

name: PR Build

on:
pull_request:
branches: [ main ]

env:
IMAGE_NAME: aws-otel-collector
PACKAGING_ROOT: build/packages

jobs:

build:
runs-on: ubuntu-latest

steps:
# Set up building environment, patch the dev repo code on dispatch events.
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13

- uses: actions/checkout@v2

# Unit Test and attach test coverage badge
- name: Unit Test
run: make test

- name: Upload Coverage report to CodeCov
uses: codecov/codecov-action@v1.0.12
with:
file: ./coverage.txt

# Build and archive binaries into cache.
- name: Build Binaries
run: make build

- name: Cache binaries
uses: actions/cache@v2
with:
key: "cached_binaries_${{ github.run_id }}"
path: build

# upload the binaries to artifact as well because cache@v2 hasn't support windows
- name: Upload
uses: actions/upload-artifact@v2
with:
name: binary_artifacts
path: build

packaging-msi:
needs: build
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: binary_artifacts
path: build

- name: Display structure of downloaded files
run: ls -R

- name: Create msi file using candle and light
run: .\tools\packaging\windows\create_msi.ps1

packaging-rpm:
runs-on: ubuntu-latest
needs: build
steps:
# Build and archive rpms into cache.
- uses: actions/checkout@v2

- name: restore cached binaries
uses: actions/cache@v2
with:
key: "cached_binaries_${{ github.run_id }}"
path: build

- name: Display structure of downloaded files
run: ls -R

- name: Build RPM
run: |
ARCH=x86_64 DEST=build/packages/linux/amd64 tools/packaging/linux/create_rpm.sh
ARCH=aarch64 DEST=build/packages/linux/arm64 tools/packaging/linux/create_rpm.sh
packaging-deb:
runs-on: ubuntu-latest
needs: build
steps:
# Build and archive debs into cache.
- uses: actions/checkout@v2

- name: restore cached binaries
uses: actions/cache@v2
with:
key: "cached_binaries_${{ github.run_id }}"
path: build

- name: Build Debs
run: |
ARCH=amd64 TARGET_SUPPORTED_ARCH=x86_64 DEST=build/packages/debian/amd64 tools/packaging/debian/create_deb.sh
ARCH=arm64 TARGET_SUPPORTED_ARCH=aarch64 DEST=build/packages/debian/arm64 tools/packaging/debian/create_deb.sh
get-test-cases:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2.1.4

- name: Get all the testing suites
id: set-matrix
run: |
matrix=$(python e2etest/get-testcases.py local_matrix)
echo "::set-output name=matrix::$matrix"
- name: List testing suites
run: |
echo ${{ steps.set-matrix.outputs.matrix }}
run-test-case:
runs-on: ubuntu-latest
needs: [get-test-cases]
strategy:
matrix: ${{ fromJson(needs.get-test-cases.outputs.matrix) }}

steps:
- name: Check out testing framework
uses: actions/checkout@v2
with:
repository: 'aws-observability/aws-otel-collector-test-framework'
path: testing-framework

- name: Check out Collector
uses: actions/checkout@v2
with:
path: aws-otel-collector

- name: Set up JDK 1.11
uses: actions/setup-java@v1
with:
java-version: 1.11

- name: Set up terraform
uses: hashicorp/setup-terraform@v1

- name: Run test
run: |
if [[ -f testing-framework/terraform/testcases/${{ matrix.testcase }}/parameters.tfvars ]] ; then opts="-var-file=../testcases/${{ matrix.testcase }}/parameters.tfvars" ; else opts="" ; fi
cd testing-framework/terraform/mock && terraform init && terraform apply -auto-approve -var="testcase=../testcases/${{ matrix.testcase }}" $opts
5 changes: 4 additions & 1 deletion e2etest/get-testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
ec2_matrix = {"testcase": [], "testing_ami": ["amazonlinux2", "ubuntu16", "windows2019"]}
ecs_matrix = {"testcase": [], "launch_type": ["EC2", "FARGATE"]}
eks_matrix = {"testcase": []}
matrix = {"ec2_matrix": ec2_matrix, "ecs_matrix": ecs_matrix, "eks_matrix": eks_matrix}
local_matrix = {"testcase": []}
matrix = {"ec2_matrix": ec2_matrix, "ecs_matrix": ecs_matrix, "eks_matrix": eks_matrix, "local_matrix": local_matrix}

with open(testcase_json) as f:
testcases = json.load(f)
Expand All @@ -21,5 +22,7 @@
ecs_matrix["testcase"].append(testcase["case_name"])
if 'EKS' in testcase["platforms"]:
eks_matrix["testcase"].append(testcase["case_name"])
if 'LOCAL' in testcase["platforms"]:
local_matrix["testcase"].append(testcase["case_name"])

print(json.dumps(matrix[which_matrix]))
8 changes: 8 additions & 0 deletions e2etest/testcases.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"case_name": "otlp",
"platforms": ["EC2", "ECS", "EKS"]
},
{
"case_name": "otlp_mock",
"platforms": ["LOCAL"]
},
{
"case_name": "xrayreceiver_mock",
"platforms": ["LOCAL"]
},
{
"case_name": "ecsmetrics",
"platforms": ["ECS"]
Expand Down

0 comments on commit 8719306

Please sign in to comment.