Skip to content

Commit

Permalink
git action update
Browse files Browse the repository at this point in the history
  • Loading branch information
sodyn99 committed Jun 27, 2024
1 parent 47c4c1b commit e53e17f
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 28 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ jobs:
with:
go-version-file: 'go.mod'
- name: Build
run: |
go build -o build/_output/onos-topo ./cmd/onos-topo
go build -o build/_output/topo-generator ./cmd/topo-generator
go build -o build/_output/topo-visualizer ./cmd/topo-visualizer
run: make build
lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -41,7 +38,7 @@ jobs:
with:
go-version-file: 'go.mod'
- name: Unit tests
run: go test -race ./...
run: make test #go test -race ./...

docker-build:
runs-on: ubuntu-latest
Expand All @@ -51,11 +48,8 @@ jobs:
with:
go-version-file: 'go.mod'
- name: Build Docker image
run: |
git clone https://github.com/onosproject/build-tools.git build/build-tools
go mod vendor
docker build . -f build/onos-topo/Dockerfile -t onosproject/onos-topo:latest
rm -rf vendor
run: make images

license-check:
runs-on: ubuntu-latest
steps:
Expand Down
190 changes: 190 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation
# Copyright 2024 Kyunghee University
name: GitHub release and Docker images

on:
push:
branches:
- master
tags:
- v*

jobs:
push-images:
runs-on: ubuntu-latest
if: github.repository_owner == 'khu-mcl'
env:
REGISTRY: docker.io
DOCKER_REPOSITORY: khusdran/
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

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

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

- uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image with tag latest
env:
DOCKER_TAG: latest
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
git clone https://github.com/onosproject/build-tools.git build/build-tools
make images
make docker-push
# CAUTION: Other actions depend on this name "tag-github"
tag-github:
runs-on: ubuntu-latest
if: github.repository_owner == 'khu-mcl'
outputs:
changed: ${{ steps.version-change.outputs.changed }}
version: ${{ steps.version-change.outputs.version }}
release_branch: ${{ steps.version-change.outputs.release_branch }}
version_branch: ${{ steps.version-change.outputs.version_branch }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get changes
id: version-file
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep VERSION; then
echo "changed=true" >> $GITHUB_OUTPUT
version_before=$(git show ${{ github.event.before }}:VERSION)
echo "version_before=$version_before" >> $GITHUB_OUTPUT
else
echo "VERSION file was not changed"
fi
- name: Validate change in version file
id: version-change
if: steps.version-file.outputs.changed == 'true'
run: |
version=$(cat VERSION)
version_before_full=${{ steps.version-file.outputs.version_before }}
version_before=${version_before_full::-4}
echo "version=$version"
echo "version_before=$version_before"
validate="^[0-9]+\.[0-9]+\.[0-9]+$"
if [[ $version =~ $validate ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
else
echo "Version change not for release"
fi
if [[ $version_before =~ $validate ]]; then
IFS='.' read -r major minor patch <<< "$version"
IFS='.' read -r major_b minor_b patch_b <<< "$version_before"
if [[ "$major" -ne "$major_b" ]] || [[ "$minor" -ne "$minor_b" ]]; then
version_branch="$major_b.$minor_b"
echo "release_branch=true" >> $GITHUB_OUTPUT
echo "version_branch=$version_branch" >> $GITHUB_OUTPUT
fi
else
echo "Version change not for branch release"
fi
- name: Create release using REST API
if: steps.version-change.outputs.changed == 'true'
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{
"tag_name": "v${{ steps.version-change.outputs.version }}",
"target_commitish": "${{ github.event.repository.default_branch }}",
"name": "v${{ steps.version-change.outputs.version }}",
"draft": false,
"prerelease": false,
"generate_release_notes": true
}'
release-image:
runs-on: ubuntu-latest
needs: tag-github
if: needs.tag-github.outputs.changed == 'true'
env:
REGISTRY: docker.io
DOCKER_REPOSITORY: khusdran/
steps:
- uses: actions/checkout@v4

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

- uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push release Docker image
env:
DOCKER_TAG: ${{ needs.tag-github.outputs.version }}
run: |
git clone https://github.com/onosproject/build-tools.git build/build-tools
make images
make docker-push
update-version:
runs-on: ubuntu-latest
needs: tag-github
if: needs.tag-github.outputs.changed == 'true'
steps:
- uses: actions/checkout@v4

- name: Increment version
run: |
version=${{ needs.tag-github.outputs.version }}
IFS='.' read -r major minor patch <<< "$version"
patch_update=$((patch+1))
NEW_VERSION="$major.$minor.$patch_update-dev"
echo $NEW_VERSION > VERSION
echo "Updated version: $NEW_VERSION"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GH_TOKEN }}
commit-message: Update version
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: version-update
delete-branch: true
title: Update version
body: |
Update VERSION file
add-paths: |
VERSION
# branch-release:
# runs-on: ubuntu-latest
# needs: tag-github
# if: (needs.tag-github.outputs.changed == 'true') && (needs.tag-github.outputs.release_branch == 'true')
# env:
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
# steps:
# - uses: actions/checkout@v4
#
# - uses: peterjgrainger/[email protected]
# with:
# branch: "rel-${{ needs.tag-github.outputs.version_branch }}"
# sha: '${{ github.event.pull_request.head.sha }}'
25 changes: 25 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation
name: Stale issue/pr

on:
schedule:
- cron: "0 0 * * *"

env:
DAYS_BEFORE_STALE: 120
DAYS_BEFORE_CLOSE: 15

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been stale for ${{ env.DAYS_BEFORE_STALE }} days and will be closed in ${{ env.DAYS_BEFORE_CLOSE }} days. Comment to keep it open.'
stale-pr-message: 'This pull request has been stale for ${{ env.DAYS_BEFORE_STALE }} days and will be closed in ${{ env.DAYS_BEFORE_CLOSE }} days. Comment to keep it open.'
stale-issue-label: 'stale/issue'
stale-pr-label: 'stale/pr'
days-before-stale: ${{ env.DAYS_BEFORE_STALE }}
days-before-close: ${{ env.DAYS_BEFORE_CLOSE }}
37 changes: 19 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ export CGO_ENABLED=1
export GO111MODULE=on

.PHONY: build

ONOS_TOPO_VERSION := latest
TARGET := onos-topo
TARGET_TEST := onos-topo-test
DOCKER_TAG ?= latest
PLATFORM ?= --platform linux/x86_64

build: # @HELP build the Go binaries and run all validations (default)
build:
CGO_ENABLED=1 go build -o build/_output/onos-topo ./cmd/onos-topo
CGO_ENABLED=1 go build -o build/_output/${TARGET} ./cmd/${TARGET}
go build -o build/_output/topo-generator ./cmd/topo-generator
go build -o build/_output/topo-visualizer ./cmd/topo-visualizer

Expand All @@ -29,41 +30,41 @@ mod-lint: mod-update # @HELP ensure that the required dependencies are in place

test: # @HELP run the unit tests and source code validation producing a golang style report
test: mod-lint build linters license
go test -race github.com/onosproject/onos-topo/...
go test -race github.com/onosproject/${TARGET}/...

jenkins-test: # @HELP run the unit tests and source code validation producing a junit style report for Jenkins
jenkins-test: mod-lint build linters license
TEST_PACKAGES=github.com/onosproject/onos-topo/pkg/... ./build/build-tools/build/jenkins/make-unit
#jenkins-test: # @HELP run the unit tests and source code validation producing a junit style report for Jenkins
#jenkins-test: mod-lint build linters license
TEST_PACKAGES=github.com/onosproject/${TARGET}/pkg/... ./build/build-tools/build/jenkins/make-unit

helmit-topo: integration-test-namespace # @HELP run helmit gnmi tests locally
make helmit-topo -C test

integration-tests: helmit-topo

onos-topo-docker: # @HELP build onos-topo base Docker image
docker-build: # @HELP build onos-topo base Docker image
@go mod vendor
docker build ${PLATFORM} . -f build/onos-topo/Dockerfile \
-t onosproject/onos-topo:${ONOS_TOPO_VERSION}
docker build ${PLATFORM} . -f build/${TARGET}/Dockerfile \
-t ${DOCKER_REPOSITORY}${TARGET}:${DOCKER_TAG}
@rm -rf vendor

images: # @HELP build all Docker images
images: build onos-topo-docker
images: build docker-build

kind: # @HELP build Docker images and add them to the currently configured kind cluster
kind: images
@if [ "`kind get clusters`" = '' ]; then echo "no kind cluster found" && exit 1; fi
kind load docker-image onosproject/onos-topo:${ONOS_TOPO_VERSION}
kind load docker-image ${DOCKER_REPOSITORY}${TARGET}:${DOCKER_TAG}

all: build images

publish: # @HELP publish version on github and dockerhub
./build/build-tools/publish-version ${VERSION} onosproject/onos-topo
./build/build-tools/publish-version ${VERSION} ${DOCKER_REPOSITORY}${TARGET}

jenkins-publish: jenkins-tools # @HELP Jenkins calls this to publish artifacts
./build/bin/push-images
./build/build-tools/release-merge-commit
./build/build-tools/build/docs/push-docs
#jenkins-publish: jenkins-tools # @HELP Jenkins calls this to publish artifacts
# ./build/bin/push-images
# ./build/build-tools/release-merge-commit
# ./build/build-tools/build/docs/push-docs

clean:: # @HELP remove all the build artifacts
rm -rf ./build/_output ./vendor ./cmd/onos-topo/onos-topo ./cmd/dummy/dummy
rm -rf ./build/_output ./vendor ./cmd/${TARGET}/${TARGET} ./cmd/dummy/dummy

0 comments on commit e53e17f

Please sign in to comment.