Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
george012 committed Jun 20, 2024
1 parent 87f1b60 commit 1342ad0
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 44 deletions.
108 changes: 66 additions & 42 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
name: BuildAndPackage
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go build

env:
ProJectName: "ltc_scrypt_go"
ProductName: ltc_scrypt_go

on:
workflow_dispatch:
push:
tags:
- "v*"
- 'v*'

jobs:
release:
Testing:
strategy:
matrix:
os: [macos-latest]
arch: [amd64, arm64]
exclude:
- os: windows-latest
arch: arm64
runs-on: ${{ matrix.os }}

steps:
- name: CheckOut
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '>=1.18.0'

- name: do testing
run: |
go test -v ./...
Release:
runs-on: ubuntu-latest
needs: Testing
outputs:
UPLOAD_URL: ${{ steps.stepCreateRelease.outputs.upload_url }}
steps:
Expand All @@ -20,7 +46,7 @@ jobs:

- name: Get latest tag
run: |
echo "LATEST_TAG=$(git tag | grep -v '^latest$' | sort -V | tail -n1)" >> $GITHUB_ENV
echo "LATEST_TAG=$(git tag | grep -v '^latest$' | sort -V | tail -n1)" >> ${GITHUB_ENV}
- name: Bump version and push tag
id: tag-version
Expand All @@ -38,43 +64,9 @@ jobs:
tag: ${{ env.LATEST_TAG }}
name: ${{ env.LATEST_TAG }}

buildOnMacOS:
runs-on: macos-latest
needs: release
steps:
- name: CheckOut
uses: actions/checkout@v4

- name: install dependencies
run: |
brew install tree zip unzip openssl FiloSottile/musl-cross/musl-cross mingw-w64 mingw-w64-openssl
- name: Set up JDK 1.8
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'

- name: Set up Android NDK
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r26d

- name: Build static library
run: |
chmod a+x ./build.sh
./build.sh all
- name: Upload binaries to release
id: upload_file_to_release
uses: george012/upload_github_release_assets_action@latest
with:
path: ./build/*.zip

RemoveOldRelease:
runs-on: ubuntu-latest
needs: [buildOnMacOS]
needs: Release
steps:
- name: install github-cli
run: |
Expand All @@ -91,7 +83,39 @@ jobs:
- name: Set APP_VERSION env
run: |
APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) \
&& echo APP_OLD_VERSION=${APP_VERSION%.*}.$((${APP_VERSION##*.}-2)) >> ${GITHUB_ENV}
function get_pre_del_tag {
local v_str=$1
baseStr=$(echo $v_str | cut -d'.' -f1)
base=${baseStr//v/}
major=$(echo $v_str | cut -d'.' -f2)
minor=$(echo $v_str | cut -d'.' -f3)
if ((minor>0)); then
minor=$((minor-1))
else
minor=999
if ((major>0)); then
major=$((major-1))
else
major=999
if ((base>0)); then
base=$((base-1))
else
echo "Error: Version cannot be decremented."
exit 1
fi
fi
fi
pre_v_no="v${base}.${major}.${minor}"
echo $pre_v_no
}
APP_OLD_VERSION=$(get_pre_del_tag $(get_pre_del_tag $APP_VERSION))
echo "Old version to remove: ${APP_OLD_VERSION}"
echo APP_OLD_VERSION=${APP_OLD_VERSION} >> ${GITHUB_ENV}
- name: Remove Old Release
run: |
Expand Down
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
# ltc_scrypt_go

## Test
<!-- TOC -->

- [1. info](#1-info)
- [depends_Linux](#depends_linux)
- [depends_Darwin](#depends_darwin)
- [depends_Windows](#depends_windows)
- [1.1. Test](#11-test)

<!-- /TOC -->

# 1. info
* copy with [github.com/litecoin-project/litecoin](https://github.com/litecoin-project/litecoin)
* copy `scrypt.cpp` [litecoin/src/crypto/scrypt.cpp](https://github.com/litecoin-project/litecoin/tree/master/src/crypto/scrypt.cpp)
* copy `scrypt.h` [litecoin/src/crypto/scrypt.h](https://github.com/litecoin-project/litecoin/tree/master/src/crypto/scrypt.h)

# depends_Linux
```
Linux
apt udpate
apt install openssl libssl-dev
```

# depends_Darwin
```
brew install openssl
```

# depends_Windows
* msys2 and mingw64
```
pacman -Syu mingw64-toolchain
```


# 1.1. Test
```
go test -v -run ./...
Expand All @@ -16,4 +51,9 @@ export OPENSSL_LIBRARIES=$OPENSSL_ROOT_DIR/lib
export OPENSSL_INCLUDE_DIR=$OPENSSL_ROOT_DIR/include
export PKG_CONFIG_PATH=$OPENSSL_ROOT_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
Linux
apt udpate
apt install openssl libssl-dev
```
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

const (
ProjectName = "ltc_scrypt_go"
ProjectVersion = "v0.0.1"
)
7 changes: 7 additions & 0 deletions extend_funcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ltc_scrypt_go

import "github.com/george012/ltc_scrypt_go/config"

func GetVersion() string {
return config.ProjectVersion
}
150 changes: 150 additions & 0 deletions git_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#!/bin/bash

set -e

ProductName=$(grep ProjectName ./config/config.go | awk -F '"' '{print $2}' | sed 's/\"//g')
Product_version_key="ProjectVersion"
REPO_PFEX=george012/$ProductName
VersionFile=./config/config.go

CURRENT_VERSION=$(grep ${Product_version_key} $VersionFile | awk -F '"' '{print $2}' | sed 's/\"//g')

NEXT_VERSION=""

OS_TYPE="Unknown"
GetOSType() {
uNames=`uname -s`
osName=${uNames: 0: 4}
if [ "$osName" == "Darw" ] # Darwin
then
OS_TYPE="Darwin"
elif [ "$osName" == "Linu" ] # Linux
then
OS_TYPE="Linux"
elif [ "$osName" == "MING" ] # MINGW, windows, git-bash
then
OS_TYPE="Windows"
else
OS_TYPE="Unknown"
fi
}
GetOSType

function to_run() {
if [ -z "$1" ]; then
baseStr=$(echo ${CURRENT_VERSION} | cut -d'.' -f1) # Get the base version (v0)
base=${baseStr//v/} # Get the base version (0)
major=$(echo ${CURRENT_VERSION} | cut -d'.' -f2) # Get the major version (0)
minor=$(echo ${CURRENT_VERSION}| cut -d'.' -f3) # Get the minor version (1)

minor=$((minor+1)) # Increment the minor version
if ((minor==1000)); then # Check if minor version is 100
minor=0 # Reset minor version to 0
major=$((major+1)) # Increment major version
fi

if ((major==1000)); then # Check if major version is 100
major=0 # Reset major version to 0
base=$((base+1)) # Increment base version
fi

NEXT_VERSION="v${base}.${major}.${minor}"
return 0
elif [ "$1" == "custom" ]; then
echo "============================ ${ProductName} ============================"
echo " 1、发布 [-${ProductName}-]"
echo " 当前版本[-${CURRENT_VERSION}-]"
echo "======================================================================"
read -p "$(echo -e "请输入版本号[例如;v0.0.1]")" inputString
if [[ "$inputString" =~ ^v.* ]]; then
NEXT_VERSION=${inputString}
else
NEXT_VERSION=v${inputString}
fi
return 0
else
return 1
fi
}

function get_pre_del_version_no {
local v_str=$1
baseStr=$(echo $v_str | cut -d'.' -f1) # Get the base version (v0)
base=${baseStr//v/} # Get the base version (0)
major=$(echo $v_str | cut -d'.' -f2) # Get the major version (0)
minor=$(echo $v_str | cut -d'.' -f3) # Get the minor version (1)

if ((minor>0)); then # Check if minor version is more than 0
minor=$((minor-1)) # Decrement the minor version
else
minor=999 # Reset minor version to 99
if ((major>0)); then # Check if major version is more than 0
major=$((major-1)) # Decrement major version
else
major=999 # Reset major version to 99
if ((base>0)); then # Check if base version is more than 0
base=$((base-1)) # Decrement base version
else
echo "Error: Version cannot be decremented."
exit 1
fi
fi
fi

pre_v_no="${base}.${major}.${minor}"
echo $pre_v_no
}

function git_handle_ready() {
echo "Current Version With "${CURRENT_VERSION}
echo "Next Version With "${NEXT_VERSION}

sed -i -e "s/\(${Product_version_key}[[:space:]]*=[[:space:]]*\"\)${CURRENT_VERSION}\"/\1${NEXT_VERSION}\"/" $VersionFile

if [[ $OS_TYPE == "Darwin" ]]; then
echo "rm darwin cache"
rm -rf $VersionFile"-e"
fi
}

function git_handle_push() {
local current_version_no=${CURRENT_VERSION//v/}
local next_version_no=${NEXT_VERSION//v/}
local pre_del_version_no=$(get_pre_del_version_no "$current_version_no")
echo "Pre Del Version With v"${pre_del_version_no}

git add . \
&& git commit -m "Update v${next_version_no}" \
&& git tag v${next_version_no} \
&& git tag -f latest v${next_version_no}

for remote in $(git remote)
do
echo "Pushing to ${remote}..."
git push --delete ${remote} latest \
&& git push ${remote} \
&& git push ${remote} v${next_version_no} \
&& git push ${remote} latest
done
git tag -d v${pre_del_version_no}
}

handle_input(){
if [[ $1 == "-get_pre_del_tag_name" ]]; then
pre_tag=$(get_pre_del_version_no "${CURRENT_VERSION}")
echo "Pre Del Tag With " "$pre_tag"
elif [ -z "$1" ] || [ "$1" == "auto" ]; then

if to_run "$1"; then
git_handle_ready
git_handle_push
echo "Complated"
else
echo "Invalid argument normal"
fi
else
echo "Invalid argument"
fi
}

handle_input "$@"

0 comments on commit 1342ad0

Please sign in to comment.