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

update post pr merge process to add tag and publish images #121

Merged
merged 1 commit into from
Jun 27, 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
124 changes: 124 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation
# Copyright 2024 Kyunghee University
name: Publish image and tag/release code

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

jobs:
version-check:
runs-on: ubuntu-latest
outputs:
valid_version: ${{ steps.version-check.outputs.valid_version }}
dev_version: ${{ steps.version-check.outputs.dev_version }}
target_version: ${{ steps.version-check.outputs.target_version }}
steps:
- uses: actions/checkout@v4
- name: check version
id: version-check
run: |
make check-version; if [[ $? == 0 ]]; then echo "valid_version=true" >> $GITHUB_OUTPUT; else echo "valid_version=false" >> $GITHUB_OUTPUT; fi
./build/bin/version_check.sh is_dev; if [[ $? == 0 ]]; then echo "dev_version=true" >> $GITHUB_OUTPUT; else echo "dev_version=false" >> $GITHUB_OUTPUT; fi
echo "target_version=$(cat VERSION)" >> $GITHUB_OUTPUT

tag_versions:
runs-on: ubuntu-latest
needs: version-check
if: (github.repository_owner == 'onosproject') && (needs.version-check.outputs.valid_version == 'true') && (needs.version-check.outputs.dev_version == 'false')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: create release using REST API
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_ONOS_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{
"tag_name": "v${{ needs.version-check.outputs.target_version }}",
"target_commitish": "${{ github.event.repository.default_branch }}",
"name": "v${{ needs.version-check.outputs.target_version }}",
"draft": false,
"prerelease": false,
"generate_release_notes": true
}'

publish-images:
runs-on: ubuntu-latest
needs: version-check
if: (github.repository_owner == 'onosproject') && (needs.version-check.outputs.valid_version == 'true')
env:
REGISTRY: docker.io
DOCKER_REPOSITORY: onosproject/
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image with tag latest
env:
DOCKER_TAG: latest
run: |
ONOS_PCI_VERSION=${{ env.DOCKER_TAG }} make docker-build
ONOS_PCI_VERSION=${{ env.DOCKER_TAG }} make docker-push
- name: Build and push Docker image with tag
if: needs.version-check.outputs.dev_version == 'false'
env:
DOCKER_TAG: v${{ needs.version-check.outputs.target_version }}
run: |
ONOS_PCI_VERSION=${{ env.DOCKER_TAG }} make docker-build
ONOS_PCI_VERSION=${{ env.DOCKER_TAG }} make docker-push

bump-up-version:
runs-on: ubuntu-latest
needs: version-check
if: (github.repository_owner == 'onosproject') && (needs.version-check.outputs.valid_version == 'true') && (needs.version-check.outputs.dev_version == 'false')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: increment version
run: |
IFS='.' read -r major minor patch <<< ${{ needs.version-check.outputs.target_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_ONOS_PAT }}
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
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export GO111MODULE=on

.PHONY: build

ONOS_PCI_VERSION := latest
ONOS_PCI_VERSION ?= latest
ONOS_PROTOC_VERSION := v0.6.6
BUF_VERSION := 0.27.1

Expand All @@ -32,6 +32,12 @@ docker-build-onos-pci: # @HELP build onos-pci Docker image
docker-build: # @HELP build all Docker images
docker-build: build docker-build-onos-pci

docker-push-onos-pci: # @HELP push onos-pci Docker image
docker push onosproject/onos-pci:${ONOS_PCI_VERSION}

docker-push: # @HELP push docker images
docker-push: docker-push-onos-pci

lint: # @HELP examines Go source code and reports coding problems
golangci-lint --version | grep $(GOLANG_CI_VERSION) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b `go env GOPATH`/bin $(GOLANG_CI_VERSION)
golangci-lint run --timeout 15m
Expand All @@ -45,7 +51,7 @@ license: # @HELP run license checks
reuse lint

check-version: # @HELP check version is duplicated
./build/bin/version_check.sh
./build/bin/version_check.sh all

clean: # @HELP remove all the build artifacts
rm -rf ./build/_output ./vendor ./cmd/onos-pci/onos-pci ./cmd/onos/onos venv
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.11-dev
0.4.11
103 changes: 79 additions & 24 deletions build/bin/version_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,82 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation

# check if version format is matched to SemVer
VER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
if [[ ! $(cat VERSION | tr -d '\n' | tr -d "\-dev") =~ $VER_REGEX ]]
then
echo "ERROR: Version $(cat VERSION) is not in SemVer format"
exit 2
fi

# check if version has '-dev'
# if there is, no need to check version
if [[ $(cat VERSION | tr -d '\n' | tail -c 4) == "-dev" ]]
then
exit 0
fi

# check if the version is already tagged in GitHub repository
for t in $(git tag | cat)
do
if [[ $t == $(echo v$(cat VERSION | tr -d '\n')) ]]
then
echo "ERROR: duplicated tag: $t"
exit 2
fi
done
# input should be all, is_valid_format, is_dev, and is_unique
INPUT=$1

function is_valid_format() {
# check if version format is matched to SemVer
VER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
if [[ ! $(cat VERSION | tr -d '\n' | sed s/-dev//) =~ $VER_REGEX ]]
then
return 1
fi
return 0
}

function is_dev_version() {
# check if version has '-dev'
# if there is, no need to check version
if [[ $(cat VERSION | tr -d '\n' | tail -c 4) =~ "-dev" ]]
then
return 0
fi
return 1
}

function is_unique_version() {
# check if the version is already tagged in GitHub repository
for t in $(git tag | cat)
do
if [[ $t == $(echo v$(cat VERSION | tr -d '\n')) ]]
then
return 1
fi
done
return 0
}

case $INPUT in
all)
is_valid_format
f_valid=$?
if [[ $f_valid == 1 ]]
then
echo "ERROR: Version $(cat VERSION) is not in SemVer format"
exit 2
fi

is_dev_version
f_dev=$?
if [[ $f_dev == 0 ]]
then
echo "This is dev version"
exit 0
fi

is_unique_version
f_unique=$?
if [[ $f_unique == 1 ]]
then
echo "ERROR: duplicated tag $(cat VERSION)"
exit 2
fi
;;

is_valid_format)
is_valid_format
;;

is_dev)
is_dev_version
;;

is_unique)
is_unique_version
;;

*)
echo -n "unknown input"
;;

esac