Skip to content

Commit

Permalink
Refactor GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
gab-arrobo committed Mar 14, 2024
1 parent 847dc79 commit db9536b
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 111 deletions.
20 changes: 20 additions & 0 deletions .github/Dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
72 changes: 72 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022-present Open Networking Foundation

name: Publish pfcpsim
on:
push:
branches:
- main

jobs:
push-images:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 20
env:
DOCKER_REPO: 'opennetworking/pfcpsim'

steps:
- name: Checkout this repository
uses: actions/checkout@v4

- name: Read version file
run: echo VERSION=$(cat ./VERSION) >> $GITHUB_ENV

- name: Build protobuf
id: check
run: |
make build-proto
echo "::set-output name=PORCELAIN::`git status --porcelain`"
# Verify that protobuf is in sync with changes
- name: Check protobuf is sync
if: ${{ steps.check.outputs.PORCELAIN != '' }}
uses: actions/github-script@v3
with:
script: |
core.setFailed('Please run make build-proto and commit changes to compiled protobuf')
- uses: docker/login-action@v3.1.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get short SHA
run: echo GIT_SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV

- name: Build with Docker
uses: docker/build-push-action@v5
with:
context: .
push: false
load: true
tags: |
${{ env.DOCKER_REPO }}:${{ env.VERSION }}
${{ env.DOCKER_REPO }}:latest
${{ env.DOCKER_REPO }}:${{ env.GIT_SHA_SHORT }}
target: 'pfcpsim'

- name: Test docker build
run: |
docker run --rm ${{ env.DOCKER_REPO }}:latest --help
docker run --rm --entrypoint pfcpctl ${{ env.DOCKER_REPO }}:latest --help
- name: Push to registry
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.DOCKER_REPO }}:${{ env.VERSION }}
${{ env.DOCKER_REPO }}:latest
${{ env.DOCKER_REPO }}:${{ env.GIT_SHA_SHORT }}
target: 'pfcpsim'
27 changes: 0 additions & 27 deletions .github/workflows/golangci-lint.yml

This file was deleted.

99 changes: 41 additions & 58 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022-present Open Networking Foundation
# Copyright 2024-present Intel Corporation

name: Publish pfcpsim
name: Master workflow
on:
push:
branches:
Expand All @@ -10,79 +11,48 @@ on:

jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 20
env:
DOCKER_REPO: 'opennetworking/pfcpsim'

steps:
- name: Checkout this repository
uses: actions/checkout@v2

- name: Read version file
run: echo VERSION=$(cat ./VERSION) >> $GITHUB_ENV
- uses: actions/checkout@v4

- name: Build protobuf
id: check
run: |
make build-proto
echo "::set-output name=PORCELAIN::`git status --porcelain`"
# Verify that protobuf is in sync with changes
- name: Check protobuf is sync
if: ${{ steps.check.outputs.PORCELAIN != '' }}
uses: actions/github-script@v3
- uses: actions/setup-go@v5
with:
script: |
core.setFailed('Please run make build-proto and commit changes to compiled protobuf')
go-version-file: 'go.mod'

- name: Login to DockerHub
uses: docker/login-action@v1
# perform login only on main branch
if: ${{ github.ref == 'refs/heads/main' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build
run: go build ./...

- name: Get short SHA
run: echo GIT_SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build Docker image
run: make docker-build

lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build with Docker
uses: docker/build-push-action@v2
- uses: actions/setup-go@v5
with:
context: .
push: false
load: true
tags: |
${{ env.DOCKER_REPO }}:${{ env.VERSION }}
${{ env.DOCKER_REPO }}:latest
${{ env.DOCKER_REPO }}:${{ env.GIT_SHA_SHORT }}
target: 'pfcpsim'

- name: Test docker build
run: |
docker run --rm ${{ env.DOCKER_REPO }}:latest --help
docker run --rm --entrypoint pfcpctl ${{ env.DOCKER_REPO }}:latest --help
go-version-file: 'go.mod'

- name: Push to registry
uses: docker/build-push-action@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v4.0.0
with:
context: .
# build on feature branches, push only on main branch
push: ${{ github.ref == 'refs/heads/main' }}
tags: |
${{ env.DOCKER_REPO }}:${{ env.VERSION }}
${{ env.DOCKER_REPO }}:latest
${{ env.DOCKER_REPO }}:${{ env.GIT_SHA_SHORT }}
target: 'pfcpsim'
version: latest
args: -v --config ./.golangci.yml

license-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: reuse lint
uses: fsfe/reuse-action@v2
uses: fsfe/reuse-action@v3

fossa-check:
runs-on: ubuntu-latest
Expand All @@ -92,4 +62,17 @@ jobs:
- name: FOSSA scan
uses: fossa-contrib/fossa-action@v3
with:
fossa-api-key: 9dc8fa92e3dd565687317beb87b56d89
fossa-api-key: 0c3bbcdf20e157bbd487dae173751b28

unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Run unit tests for PFCPSim
run: |
make test
21 changes: 0 additions & 21 deletions .github/workflows/run-unit-test.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ DOCKER_TAG ?= ${VERSION}
DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${PROJECT_NAME}:${DOCKER_TAG}
DOCKER_BUILDKIT ?= 1

DOCKER_TARGET ?= pfcpsim
DOCKER_TARGET ?= pfcpsim

build-pfcpsim:
docker-build:
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build -f Dockerfile . \
--target $(DOCKER_TARGET) \
--cache-from ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}$(DOCKER_TARGET):${DOCKER_TAG} \
Expand Down
6 changes: 3 additions & 3 deletions pkg/pfcpsim/pfcpsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const (

// PFCPClient enables to simulate a client sending PFCP messages towards the UPF.
// It provides two usage modes:
// - 1st mode enables high-level PFCP operations (e.g., SetupAssociation())
// - 2nd mode gives a user more control over PFCP sequence flow
// and enables send and receive of individual messages (e.g., SendAssociationSetupRequest(), PeekNextResponse())
// - 1st mode enables high-level PFCP operations (e.g., SetupAssociation())
// - 2nd mode gives a user more control over PFCP sequence flow
// and enables send and receive of individual messages (e.g., SendAssociationSetupRequest(), PeekNextResponse())
type PFCPClient struct {
// keeps the current number of active PFCP sessions
// it is also used as F-SEID
Expand Down

0 comments on commit db9536b

Please sign in to comment.