-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
318 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Docker | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
build: | ||
strategy: | ||
matrix: | ||
os: [ 'ubuntu-latest' ] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Test Docker | ||
run: chmod +x ./scripts/build-docker.sh && ./scripts/build-docker.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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: Release | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
build: | ||
strategy: | ||
matrix: | ||
go: [ 'stable' ] | ||
os: [ 'ubuntu-latest' ] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Test Release | ||
run: chmod +x ./scripts/build-release.sh && ./scripts/build-release.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM golang:latest AS build | ||
|
||
WORKDIR /gowork | ||
|
||
ARG GOPROXY | ||
ARG CGO_ENABLED=0 | ||
|
||
COPY . . | ||
|
||
RUN echo $(git rev-parse HEAD) >internal/version/commit | ||
|
||
RUN go build -v -o . ./... | ||
|
||
FROM alpine:latest | ||
|
||
WORKDIR /app | ||
|
||
ENV PATH=$PATH:/app | ||
|
||
COPY --from=build /gowork/replacer . | ||
|
||
WORKDIR /workspace |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package about | ||
|
||
import ( | ||
"github.com/no-src/replacer/internal/version" | ||
) | ||
|
||
const logo = ` | ||
________ _______ ________ ___ ________ ________ _______ ________ | ||
|\ __ \|\ ___ \ |\ __ \|\ \ |\ __ \|\ ____\|\ ___ \ |\ __ \ | ||
\ \ \|\ \ \ __/|\ \ \|\ \ \ \ \ \ \|\ \ \ \___|\ \ __/|\ \ \|\ \ | ||
\ \ _ _\ \ \_|/_\ \ ____\ \ \ \ \ __ \ \ \ \ \ \_|/_\ \ _ _\ | ||
\ \ \\ \\ \ \_|\ \ \ \___|\ \ \____\ \ \ \ \ \ \____\ \ \_|\ \ \ \\ \| | ||
\ \__\\ _\\ \_______\ \__\ \ \_______\ \__\ \__\ \_______\ \_______\ \__\\ _\ | ||
\|__|\|__|\|_______|\|__| \|_______|\|__|\|__|\|_______|\|_______|\|__|\|__| | ||
` | ||
const ( | ||
openSourceUrl = "https://github.com/no-src/replacer" | ||
documentationUrl = "https://pkg.go.dev/github.com/no-src/replacer@" + version.VERSION | ||
releaseUrl = "https://github.com/no-src/replacer/releases" | ||
dockerImageUrl = "https://hub.docker.com/r/nosrc/replacer" | ||
) | ||
|
||
// PrintAbout print the program logo and basic info | ||
func PrintAbout(out func(format string, args ...any)) { | ||
out(logo) | ||
out("The replacer is a configuration-based file replace tool") | ||
out("Open source repository at: <%s>", openSourceUrl) | ||
out("Download the latest version at: <%s>", releaseUrl) | ||
out("The docker image repository address at: <%s>", dockerImageUrl) | ||
out("Full documentation at: <%s>", documentationUrl) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Version Info | ||
|
||
## Version | ||
|
||
The `VERSION` constant records the current version info. | ||
|
||
## Commit | ||
|
||
The `commit` file records the commit hash value of release, it is used for release build. | ||
|
||
Please do not commit the `commit` file after it changes, and keep it empty in the git repository. | ||
|
||
## GoVersion | ||
|
||
Print the version of Go being used, as well as the operating system and architecture targets of the running program. |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package version | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
// VERSION the current program version info | ||
const VERSION = "v0.0.1" | ||
|
||
// Commit the commit file records the last commit hash value, used by release | ||
// | ||
//go:embed commit | ||
var Commit string | ||
|
||
// PrintVersion print the current version info, and append the commit info if the commit file is not empty | ||
func PrintVersion(name string, out func(format string, args ...any)) { | ||
v := fmt.Sprintf("%s version %s", name, VERSION) | ||
if commit := strings.TrimSpace(Commit); len(commit) > 0 { | ||
v += fmt.Sprintf("\ngit commit %s", commit) | ||
} | ||
v += fmt.Sprintf("\ngo version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH) | ||
out(v) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
|
||
# usage | ||
# build the latest image | ||
# ./scripts/build-docker.sh | ||
# build the image with a specified tag | ||
# ./scripts/build-docker.sh v0.1.0 | ||
|
||
echo "current branch is $(git branch --show-current)" | ||
|
||
# update git repository | ||
# git pull --no-rebase | ||
|
||
# update the latest golang image | ||
docker pull golang:latest | ||
|
||
# set GOPROXY environment variable | ||
# GOPROXY=https://goproxy.cn | ||
|
||
SOFT_NAME=replacer | ||
# docker image name | ||
SOFT_IMAGE_NAME=nosrc/${SOFT_NAME} | ||
# docker image tag | ||
SOFT_IMAGE_TAG=latest | ||
|
||
# reset SOFT_IMAGE_TAG to the value of the first parameter provided by the user | ||
if [ -n "$1" ]; then | ||
SOFT_IMAGE_TAG=$1 | ||
fi | ||
|
||
# remove the existing old image | ||
docker rmi -f $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG | ||
|
||
# build Dockerfile | ||
docker build --build-arg GOPROXY=$GOPROXY -t $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG . | ||
|
||
# remove dangling images | ||
docker image prune -f | ||
|
||
docker images | grep ${SOFT_NAME} | ||
|
||
# run a container to print the soft version | ||
docker run --rm --name running-${SOFT_NAME}-version $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG ${SOFT_NAME} -v | ||
|
||
# push the image to the DockerHub | ||
# docker push $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "current branch is $(git branch --show-current)" | ||
|
||
# update repository | ||
#git pull --no-rebase | ||
|
||
# update the last git commit | ||
echo -e "$(git rev-parse HEAD)\c" >internal/version/commit | ||
|
||
# set GOPROXY environment variable | ||
# export GOPROXY=https://goproxy.cn | ||
|
||
export SOFT_RELEASE_GO_VERSION | ||
export SOFT_RELEASE_VERSION | ||
export SOFT_NAME="replacer" | ||
export SOFT_PREFIX="${SOFT_NAME}_" | ||
|
||
function init_version { | ||
go build -v -o . ./... | ||
|
||
SOFT_RELEASE_GO_VERSION=$(go version | awk '{print $3}') | ||
SOFT_RELEASE_VERSION=$(./${SOFT_NAME} -v | awk 'NR==1 {print $3}') | ||
} | ||
|
||
function build_release { | ||
# release path, for example, replacer_go1.21.1_arm64_linux_v0.1.0 | ||
SOFT_RELEASE="${SOFT_PREFIX}${SOFT_RELEASE_GO_VERSION}_${GOARCH}_${GOOS}_${SOFT_RELEASE_VERSION}" | ||
|
||
rm -rf "$SOFT_RELEASE" | ||
mkdir "$SOFT_RELEASE" | ||
|
||
# build | ||
go build -v -o . ./... | ||
|
||
if [ "$GOOS" == "windows" ]; then | ||
mv ${SOFT_NAME}.exe "$SOFT_RELEASE/" | ||
# windows release archive | ||
zip -r "$SOFT_RELEASE.zip" "$SOFT_RELEASE" | ||
else | ||
mv ${SOFT_NAME} "$SOFT_RELEASE/" | ||
# release archive | ||
tar -zcvf "$SOFT_RELEASE.tar.gz" "$SOFT_RELEASE" | ||
fi | ||
rm -rf "$SOFT_RELEASE" | ||
} | ||
|
||
init_version | ||
|
||
############################## linux-amd64-release ############################## | ||
|
||
# set go env | ||
export GOOS=linux | ||
export GOARCH=amd64 | ||
|
||
build_release | ||
|
||
############################## linux-amd64-release ############################## | ||
|
||
############################## linux-arm64-release ############################## | ||
|
||
export GOOS=linux | ||
export GOARCH=arm64 | ||
|
||
build_release | ||
|
||
############################## linux-arm64-release ############################## | ||
|
||
############################# windows-release ############################# | ||
|
||
# set go env | ||
export GOOS=windows | ||
export GOARCH=amd64 | ||
|
||
build_release | ||
|
||
############################# windows-release ############################# | ||
|
||
############################## macOS-amd64-release ############################## | ||
|
||
export GOOS=darwin | ||
export GOARCH=amd64 | ||
|
||
build_release | ||
|
||
############################## macOS-amd64-release ############################## | ||
|
||
############################## macOS-arm64-release ############################## | ||
|
||
export GOOS=darwin | ||
export GOARCH=arm64 | ||
|
||
build_release | ||
|
||
############################## macOS-arm64-release ############################## | ||
|
||
# reset commit file | ||
echo -e "\c" >internal/version/commit | ||
|
||
ls -alh | grep ${SOFT_PREFIX} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -rf logs | ||
rm -rf replacer_go* |