Merge pull request #494 from JioTV-Go/develop #268
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Build and Release" | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "README.md" | |
- "LICENSE" | |
- "docs/**" | |
- "scripts/**" | |
- "**.sh" | |
- "**.md" | |
- ".github/workflows/dependabot_action.yml" | |
- ".github/workflows/pre-release.yml" | |
- ".github/workflows/test-build.yml" | |
- ".github/workflows/docker.yml" | |
- ".github/dependabot.yml" | |
- ".github/workflows/sync-wiki.yml" | |
concurrency: | |
group: ${{ github.ref }}-release | |
cancel-in-progress: true | |
permissions: | |
contents: write | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout ποΈ | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Go π¦ | |
uses: actions/setup-go@v4 | |
with: | |
go-version-file: "go.mod" | |
- name: Increment version π | |
id: gen_tag | |
run: | | |
# setup git | |
git config user.name "GitHub Action" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
# Get the latest tag that looks like a semver tag. | |
tag=$(git describe --tags --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=0) | |
echo "Latest tag: $tag" | |
if [[ $tag == "" ]]; then | |
echo "No semver tag found, use 0.0.0" | |
tag="v0.0.0" | |
fi | |
# Get the major, minor and patch parts from the tag. | |
major_minor_patch=$(echo $tag | grep -oE "[0-9]+\.[0-9]+\.[0-9]+") | |
echo "Major, minor and patch version: $major_minor_patch" | |
major=$(echo $major_minor_patch | grep -oE "^[0-9]+") | |
minor=$(echo $major_minor_patch | grep -oE "\.[0-9]+\." | grep -oE "[0-9]+") | |
patch=$(echo $major_minor_patch | grep -oE "[0-9]+$") | |
echo "Major version: $major" | |
echo "Minor version: $minor" | |
echo "Patch version: $patch" | |
commits=$(git rev-list $tag.. --count) | |
echo "Commits since last tag: $commits" | |
# If any of commit messages contains "BREAKING" string, increment major version. | |
breaking_changes=$(git log $tag.. --pretty=%B | grep -iE "BREAKING" | wc -l) | |
echo "Breaking changes: $breaking_changes" | |
if [[ $breaking_changes -gt 0 ]]; then | |
major=$((major + 1)) | |
minor=0 | |
patch=0 | |
else | |
# Increment minor version. | |
features=$(git log $tag.. --pretty=%B | grep -iE "feat|compatibility|integration|upgrade" | wc -l) | |
echo "Features: $features" | |
if [[ $features -gt 0 ]]; then | |
minor=$((minor + 1)) | |
patch=0 | |
else | |
patch=$((patch + 1)) | |
fi | |
fi | |
# Calculate the new version number. | |
new_version="v${major}.${minor}.${patch}" | |
echo "New version: $new_version" | |
# Update the version in VERSION file | |
echo $new_version > VERSION | |
git add VERSION && git commit -m "Bump version to $new_version" && git push origin HEAD:main | |
# Mirrors tags | |
git tag -fa v$major -m "Mirror tag $new_version" | |
git tag -fa v$major.$minor -m "Mirror tag $new_version" | |
git push --tags --force | |
# Set the new tag. | |
echo "tag=$new_version" >> $GITHUB_OUTPUT | |
- name: Setup android NDK | |
run: | | |
wget -q https://dl.google.com/android/repository/android-ndk-r26b-linux.zip | |
unzip -qq android-ndk-r26b-linux.zip | |
echo "$PWD/android-ndk-r26b/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH | |
- name: Build Executables ποΈ π | |
run: | | |
mkdir -p bin | |
allowed_archs="amd64 arm arm64 386" | |
for var in $(go tool dist list); do | |
# skip disallowed archs | |
if [[ ! $allowed_archs =~ "$(cut -d '/' -f 2 <<<$var)" ]]; then | |
echo "Skipping: $var" | |
continue | |
fi | |
# skip arm for windows | |
if [[ "$(cut -d '/' -f 1 <<<$var)" == "windows" && "$(cut -d '/' -f 2 <<<$var)" == "arm" ]]; then | |
echo "Skipping: $var (windows/arm)" | |
continue | |
fi | |
file_name="jiotv_go-$(cut -d '/' -f 1 <<< $var)-$(cut -d '/' -f 2 <<< $var)" | |
case "$(cut -d '/' -f 1 <<< $var)" in | |
"windows") | |
echo "Building $var" | |
CGO_ENABLED=0 GOOS="$(cut -d '/' -f 1 <<< $var)" GOARCH="$(cut -d '/' -f 2 <<< $var)" go build -o bin/"$file_name.exe" -trimpath -ldflags="-s -w" . & | |
;; | |
"linux" | "darwin") | |
echo "Building $var" | |
CGO_ENABLED=0 GOOS="$(cut -d '/' -f 1 <<< $var)" GOARCH="$(cut -d '/' -f 2 <<< $var)" go build -o bin/"$file_name" -trimpath -ldflags="-s -w" . & | |
;; | |
"android") | |
echo "Building $var" | |
case "$(cut -d '/' -f 2 <<<$var)" in | |
"arm") | |
CGO_ENABLED=1 GOOS="$(cut -d '/' -f 1 <<<$var)" GOARCH="$(cut -d '/' -f 2 <<<$var)" CC="armv7a-linux-androideabi28-clang" CXX="armv7a-linux-androideabi28-clang++" go build -o bin/"jiotv_go-$(cut -d '/' -f 1 <<<$var)-$(cut -d '/' -f 2 <<<$var)" -trimpath -ldflags="-s -w" . | |
;; | |
"arm64") | |
CGO_ENABLED=1 GOOS="$(cut -d '/' -f 1 <<<$var)" GOARCH="$(cut -d '/' -f 2 <<<$var)" CC="aarch64-linux-android32-clang" CXX="aarch64-linux-android32-clang++" go build -o bin/"jiotv_go-$(cut -d '/' -f 1 <<<$var)-$(cut -d '/' -f 2 <<<$var)" -trimpath -ldflags="-s -w" . | |
;; | |
"amd64") | |
CGO_ENABLED=1 GOOS="$(cut -d '/' -f 1 <<<$var)" GOARCH="$(cut -d '/' -f 2 <<<$var)" CC="x86_64-linux-android32-clang" CXX="x86_64-linux-android32-clang++" go build -o bin/"jiotv_go-$(cut -d '/' -f 1 <<<$var)-$(cut -d '/' -f 2 <<<$var)" -trimpath -ldflags="-s -w" . | |
;; | |
*) | |
echo "Skipping: $var" | |
;; | |
esac | |
;; | |
*) | |
echo "Skipping: $var" | |
;; | |
esac | |
done | |
# Wait for all background jobs to finish | |
wait | |
# Build for android5 arm with CC=armv7a-linux-androideabi21-clang | |
echo "Building android5 arm" | |
CGO_ENABLED=1 GOOS=android GOARCH=arm GOARM=7 CC="armv7a-linux-androideabi21-clang" CXX="armv7a-linux-androideabi21-clang++" go build -o bin/jiotv_go-android5-armv7 -trimpath -ldflags="-s -w" . | |
- name: Release π¦ | |
uses: softprops/action-gh-release@v1 | |
with: | |
draft: false | |
prerelease: false | |
tag_name: ${{ steps.gen_tag.outputs.tag }} | |
files: | | |
./bin/* | |
generate_release_notes: true | |
discussion_category_name: releases | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} |