Merge pull request #22 #124
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: buildwithdocker-on-push | |
# !!!! IMPORTANT | |
# for this to function properly there should be NO latest tag on any commit | |
# delete latest on remote: git push origin :latest | |
# delete locally: git tag --delete latest | |
on: | |
push: | |
jobs: | |
build-and-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Number of commits to fetch. 0 indicates all history for all branches and tags. Default: 1 | |
# - run: git version | |
- run: git show-ref --tags -d --abbrev=7 | |
# the release action ("marvinpinto/action-automatic-releases@latest") uses the 'latest' lightweight tag releases work in github | |
# 'latest' is actually set by using automatic_release_tag: | |
# by using something fixed like 'latest' there is only one release that has this tag | |
# keep in mind that the tag 'latest' is only on github, since nobody fetches it back... | |
# since we have the hash, we can try to guess the version used | |
# looks like released versions are correct | |
# 'git describe --abbrev=0 --dirty' doesn't work BUT git describe does ???? | |
# therefore we use 'export GIT_TAG=${GIT_TAG_LONG::-9}' instead of the above correct one ... | |
- run: git describe | |
- name: Set version string if prerelease | |
if: ${{startsWith(github.ref, 'refs/heads/master')}} # branch master and ignore any tag see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context | |
run: | | |
export GIT_COMMIT=`git rev-parse --short HEAD` | |
export GIT_TAG_LONG=`git describe` | |
export GIT_TAG=${GIT_TAG_LONG::-9} | |
export VERSION_STRING="$GIT_TAG ($GIT_COMMIT)" | |
echo "version_string=$VERSION_STRING" >> $GITHUB_ENV | |
# the problem with getting the tagged version the same way like above is that at this point in time the tag is ONLY a lightweight one, | |
# so we have to take the tag from the context and not via 'git describe' (where we would get the previous one...) | |
- name: Set version string if tagged | |
if: ${{startsWith(github.ref, 'refs/tags/v')}} # tags start with v see https://docs.github.com/en/actions/learn-github-actions/contexts#github-context | |
run: | | |
export GIT_COMMIT=`git rev-parse --short HEAD` | |
export GIT_TAG=${{github.ref_name}} | |
export VERSION_STRING="$GIT_TAG ($GIT_COMMIT)" | |
echo "version_string=$VERSION_STRING" >> $GITHUB_ENV | |
- name: Verify GITHUB_ENV for version_string | |
run: cat $GITHUB_ENV | |
# ********** | |
# ***** start CI ***** | |
# ********** | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
install: true # use buildx as default build | |
- name: Create build dir | |
run: mkdir -p build | |
# - name: Env | |
# run: env | |
- name: Compile for linux/arm64 | |
# see https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#output this allows that all files created by docker are written somewhere | |
run: docker build . --platform linux/arm64 --build-arg VERSION_STRING="${{env.version_string}} arm64" -o type=local,dest=build/arm64 && cd build/arm64/usr/src/app && tar -czf $GITHUB_WORKSPACE/build/sdmon-arm64.tar.gz sdmon | |
- name: Compile for linux/armv7 | |
# see https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#output this allows that all files created by docker are written somewhere | |
run: docker build . --platform linux/arm/v7 --build-arg VERSION_STRING="${{env.version_string}} armv7" -o type=local,dest=build/armv7 && cd build/armv7/usr/src/app && tar -czf $GITHUB_WORKSPACE/build/sdmon-armv7.tar.gz sdmon | |
- name: Compile for linux/armv6 | |
# see https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md#output this allows that all files created by docker are written somewhere | |
run: docker build . --platform linux/arm/v6 --build-arg VERSION_STRING="${{env.version_string}} armv6" -o type=local,dest=build/armv6 && cd build/armv6/usr/src/app && tar -czf $GITHUB_WORKSPACE/build/sdmon-armv6.tar.gz sdmon | |
# ********** | |
# ***** end of CI ***** | |
# ********** | |
- name: Release if tagged | |
if: ${{startsWith(github.ref, 'refs/tags/v')}} | |
uses: "marvinpinto/action-automatic-releases@latest" | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
prerelease: false | |
files: | | |
build/sdmon-arm64.tar.gz | |
build/sdmon-armv7.tar.gz | |
build/sdmon-armv6.tar.gz | |
id: "automatic_releases_tagged" | |
- name: Release if prerelease | |
if: ${{startsWith(github.ref, 'refs/heads/master')}} | |
uses: "marvinpinto/action-automatic-releases@latest" | |
with: | |
repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
automatic_release_tag: "latest" | |
prerelease: true | |
title: "Development Build" | |
files: | | |
build/sdmon-arm64.tar.gz | |
build/sdmon-armv7.tar.gz | |
build/sdmon-armv6.tar.gz | |
id: "automatic_releases_not_tagged" |