Build Go App and Publish #18
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 App | |
run-name: Build Go App and Publish | |
on: | |
repository_dispatch: | |
types: [artalk-release] | |
env: | |
GO_VERSION: '1.21.3' | |
PKG_NAME: 'github.com/ArtalkJS/Artalk' | |
DOCKER_IMG: ghcr.io/goreleaser/goreleaser-cross | |
CACHE_DIR: /tmp/cache/docker-image | |
jobs: | |
build_publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Checkout latest tag | |
run: | | |
# fetch tags | |
git fetch --prune --unshallow --tags -f | |
# checkout latest version | |
VERSION=$(git describe --tags --abbrev=0) | |
git checkout ${VERSION} | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
# disable cache because the err `no space left on device` | |
# - name: Docker Image Cache | |
# id: docker-cache | |
# uses: actions/cache@v3 | |
# with: | |
# path: ${{ env.CACHE_DIR }} | |
# key: docker-image-go-cross-${{ env.GO_VERSION }} | |
- name: Pull Docker Image | |
# if: steps.docker-cache.outputs.cache-hit != 'true' | |
run: | | |
docker pull "${DOCKER_IMG}:v${GO_VERSION}" | |
# mkdir -p "${CACHE_DIR}" | |
# docker save -o "${CACHE_DIR}/go-cross.tar" "${DOCKER_IMG}:v${GO_VERSION}" | |
# - name: Restore Docker Image from Cache | |
# if: steps.docker-cache.outputs.cache-hit == 'true' | |
# run: docker load -i ${CACHE_DIR}/go-cross.tar | |
- name: Setup git-chglog | |
run: | | |
curl -sL $(curl -s https://api.github.com/repos/git-chglog/git-chglog/releases/latest \ | |
| grep -oP '"https://.+linux_amd64.tar.gz"' | tr -d \") | tar -C /usr/local/bin -xz git-chglog | |
git-chglog --version | |
- name: Pre Build | |
run: |- | |
mkdir -p local | |
# github token | |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" > local/.release-env | |
# changelog | |
git-chglog --config .github/chglog/config.yml ${VERSION} > local/release-notes.md | |
# copy config file | |
cp conf/artalk.example.yml artalk.yml | |
- name: Build and Release | |
run: | | |
docker run \ | |
--rm \ | |
--privileged \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
-v $(pwd)/sysroot:/sysroot \ | |
-v $(pwd):/go/src/${PKG_NAME} \ | |
-w /go/src/${PKG_NAME} \ | |
-e CGO_ENABLED=1 \ | |
--env-file local/.release-env \ | |
ghcr.io/goreleaser/goreleaser-cross:v${GO_VERSION} \ | |
release --release-notes local/release-notes.md |