Skip to content

Commit

Permalink
Add commit hash appending to xmake
Browse files Browse the repository at this point in the history
  • Loading branch information
tindy2013 committed Dec 15, 2023
1 parent 6a3e287 commit e45c45d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 60 deletions.
43 changes: 18 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Add commit id into version
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: SHA=$(git rev-parse --short HEAD) && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h
- name: Build
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir multiarch/alpine:x86-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
env:
ADD_COMMIT_HASH: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir -e ADD_COMMIT_HASH multiarch/alpine:x86-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
- name: Upload
uses: actions/upload-artifact@v3
with:
Expand All @@ -43,11 +42,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Add commit id into version
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: SHA=$(git rev-parse --short HEAD) && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h
- name: Build
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir multiarch/alpine:amd64-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
env:
ADD_COMMIT_HASH: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir -e ADD_COMMIT_HASH multiarch/alpine:amd64-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
- name: Upload
uses: actions/upload-artifact@v3
with:
Expand All @@ -68,11 +66,10 @@ jobs:
runs-on: [self-hosted, linux, ARM]
steps:
- uses: actions/checkout@v3
- name: Add commit id into version
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: SHA=$(git rev-parse --short HEAD) && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h
- name: Build
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir multiarch/alpine:armv7-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
env:
ADD_COMMIT_HASH: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir -e ADD_COMMIT_HASH multiarch/alpine:armv7-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
- name: Upload
uses: actions/upload-artifact@v3
with:
Expand All @@ -93,11 +90,10 @@ jobs:
runs-on: [self-hosted, linux, ARM64]
steps:
- uses: actions/checkout@v3
- name: Add commit id into version
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: SHA=$(git rev-parse --short HEAD) && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h
- name: Build
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir multiarch/alpine:aarch64-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
env:
ADD_COMMIT_HASH: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: docker run --rm -v $GITHUB_WORKSPACE:/root/workdir -e ADD_COMMIT_HASH multiarch/alpine:aarch64-latest-stable /bin/sh -c "apk add bash git nodejs npm && cd /root/workdir && chmod +x scripts/build.alpine.release.sh && bash scripts/build.alpine.release.sh"
- name: Upload
uses: actions/upload-artifact@v3
with:
Expand All @@ -121,10 +117,9 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Add commit id into version
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: SHA=$(git rev-parse --short HEAD) && sed -i -e 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h
- name: Build
env:
ADD_COMMIT_HASH: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: bash scripts/build.macos.release.sh
- name: Upload
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -161,10 +156,9 @@ jobs:
install: base-devel git mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-pcre2 patch mingw-w64-x86_64-xmake
msystem: MINGW64
path-type: inherit
- name: Add commit id into version
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: SHA=$(git rev-parse --short HEAD) && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h
- name: Build
env:
ADD_COMMIT_HASH: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: bash scripts/build.windows.release.sh
- name: Upload
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -201,10 +195,9 @@ jobs:
install: base-devel git mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-pcre2 patch mingw-w64-i686-xmake
msystem: MINGW32
path-type: inherit
- name: Add commit id into version
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: SHA=$(git rev-parse --short HEAD) && sed -i 's/\(v[0-9]\.[0-9]\.[0-9]\)/\1-'"$SHA"'/' src/version.h
- name: Build
env:
ADD_COMMIT_HASH: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: bash scripts/build.windows.release.sh
- name: Upload
uses: actions/upload-artifact@v3
Expand Down
44 changes: 15 additions & 29 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Publish Docker Image
on:
on:
push:
branches:
- '**'
tags:
- '**'

concurrency:
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

Expand All @@ -29,10 +29,6 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get commit SHA
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Build and export
id: build
if: startsWith(github.ref, 'refs/heads/')
Expand All @@ -43,7 +39,7 @@ jobs:
file: scripts/Dockerfile
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
ADD_COMMIT_HASH=true
outputs: type=image,push=true

- name: Replace tag without `v`
Expand All @@ -64,6 +60,8 @@ jobs:
context: .
file: scripts/Dockerfile
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
ADD_COMMIT_HASH=false
outputs: type=image,push=true

- name: Save digest
Expand Down Expand Up @@ -98,10 +96,6 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get commit SHA
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Build and export
id: build
if: startsWith(github.ref, 'refs/heads/')
Expand All @@ -112,7 +106,7 @@ jobs:
file: scripts/Dockerfile
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
ADD_COMMIT_HASH=true
outputs: type=image,push=true

- name: Replace tag without `v`
Expand All @@ -133,6 +127,8 @@ jobs:
context: .
file: scripts/Dockerfile
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
ADD_COMMIT_HASH=false
outputs: type=image,push=true

- name: Save digest
Expand All @@ -151,7 +147,7 @@ jobs:

armv7_build:
name: Build ARMv7 Image
runs-on: [self-hosted, linux, ARM]
runs-on: [ self-hosted, linux, ARM ]
steps:
- name: Checkout base
uses: actions/checkout@v3
Expand All @@ -167,10 +163,6 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get commit SHA
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Build and export
id: build
if: startsWith(github.ref, 'refs/heads/')
Expand All @@ -181,8 +173,7 @@ jobs:
file: scripts/Dockerfile
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
THREADS=4
ADD_COMMIT_HASH=true
outputs: type=image,push=true

- name: Replace tag without `v`
Expand All @@ -204,7 +195,7 @@ jobs:
file: scripts/Dockerfile
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
THREADS=4
ADD_COMMIT_HASH=false
outputs: type=image,push=true

- name: Save digest
Expand All @@ -223,7 +214,7 @@ jobs:

arm64_build:
name: Build ARM64 Image
runs-on: [self-hosted, linux, ARM64]
runs-on: [ self-hosted, linux, ARM64 ]
steps:
- name: Checkout base
uses: actions/checkout@v3
Expand All @@ -239,10 +230,6 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get commit SHA
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Build and export
id: build
if: startsWith(github.ref, 'refs/heads/')
Expand All @@ -253,8 +240,7 @@ jobs:
file: scripts/Dockerfile
tags: tindy2013/subconverter:latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
THREADS=4
ADD_COMMIT_HASH=true
outputs: type=image,push=true

- name: Replace tag without `v`
Expand All @@ -276,7 +262,7 @@ jobs:
file: scripts/Dockerfile
tags: tindy2013/subconverter:${{steps.version.outputs.result}}
build-args: |
THREADS=4
ADD_COMMIT_HASH=false
outputs: type=image,push=true

- name: Save digest
Expand All @@ -295,7 +281,7 @@ jobs:

build:
name: Build
needs: [amd64_build, x86_build, armv7_build, arm64_build]
needs: [ amd64_build, x86_build, armv7_build, arm64_build ]
runs-on: ubuntu-latest
steps:
- name: Checkout base
Expand Down
7 changes: 4 additions & 3 deletions scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM alpine:3.16 AS builder
LABEL maintainer="[email protected]"
ARG THREADS="4"
ARG SHA=""
#ARG THREADS="4"
#ARG SHA=""
ARG ADD_COMMIT_HASH="true"

# build minimized
WORKDIR /subconverter
Expand Down Expand Up @@ -44,7 +45,7 @@ RUN set -xe && \
# make -j $THREADS && \
ls -alh && \
source "$HOME/.xmake/profile" && \
xmake f --root --static=false -m release -y -v && \
xmake f --root --static=false -m release -y -v --add-commit-hash="${ADD_COMMIT_HASH:-true}" && \
xmake --root -v subconverter && \
cp "$(find build -type f -name subconverter)" . && \
python3 -m ensurepip && \
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.alpine.release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ apk add lua5.4-dev luajit-dev zlib-dev zlib-static mbedtls-dev mbedtls-static
curl -fsSL https://xmake.io/shget.text | bash
source "$HOME/.xmake/profile"

xmake f --root --static=true -m release -y -v
xmake f --root --static=true -m release -y -v --add-commit-hash="${ADD_COMMIT_HASH:-true}"
xmake --root -v subconverter
cp "$(find build -name subconverter -type f)" base/subconverter

Expand Down
2 changes: 1 addition & 1 deletion scripts/build.macos.release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ set -xe

brew reinstall xmake rapidjson pkgconfig

xmake f --root -m release -y -v
xmake f --root -m release -y -v --add-commit-hash="${ADD_COMMIT_HASH:-true}"
xmake --root -v subconverter
cp "$(find build -name subconverter -type f)" base/subconverter

Expand Down
2 changes: 1 addition & 1 deletion scripts/build.windows.release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ set -xe
## shellcheck disable=SC2046
#g++ $(find CMakeFiles/subconverter.dir/src -name "*.obj") curl/lib/libcurl.a -o base/subconverter.exe -static -lbcrypt -lpcre2-8 -l:quickjs/libquickjs.a -llibcron -lyaml-cpp -liphlpapi -lcrypt32 -lws2_32 -lwsock32 -lz -s

xmake f --root --static=true -m release -y -v
xmake f --root --static=true -m release -y -v --add-commit-hash="${ADD_COMMIT_HASH:-true}"
xmake --root -v subconverter
cp "$(find build -name subconverter.exe -type f)" base/subconverter.exe

Expand Down
14 changes: 14 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ option("static")
set_description("Build static binary.")
option_end()

option("add-commit-hash")
set_default(false)
set_showmenu(true)
set_category("option")
set_description("Add git commit hash to version.")
option_end()

add_requires("pcre2", "yaml-cpp", "rapidjson", "toml11")
includes("xmake/libcron.lua")
includes("xmake/yaml-cpp-static.lua")
Expand Down Expand Up @@ -47,6 +54,13 @@ target("subconverter")
add_defines("PCRE2_STATIC")
add_defines("YAML_CPP_STATIC_DEFINE")
add_cxxflags("-std=c++20")
if get_config("add-commit-hash") == true then
before_build(function (target)
local git_commit = string.trim(os.iorun("git rev-parse --short HEAD"))
print("git commit: " .. git_commit)
io.gsub("src/version.h", "\"(v[0-9].[0-9].[0-9])\"", "\"%1-" .. git_commit .. "\"")
end)
end

target("subconverter_lib")
set_basename("subconverter")
Expand Down

0 comments on commit e45c45d

Please sign in to comment.