-
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.
* Minor changes in README.md * Eathfile: add +multi-build and release +targets * Add ci github action * Get rid of tweeter leftovers * Skip validate_mr job during releases
- Loading branch information
Showing
3 changed files
with
134 additions
and
2 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,68 @@ | ||
name: frp-port-keeper-ci | ||
on: | ||
workflow_dispatch: | ||
push: | ||
paths-ignore: | ||
- './*.md' | ||
tags: | ||
- 'v[0-9]+.[0-9]+.*' | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
env: | ||
FORCE_COLOR: 1 | ||
|
||
jobs: | ||
# TODO: Add test job | ||
# test: | ||
|
||
validate_pr: | ||
permissions: | ||
contents: read | ||
packages: read | ||
if: ${{ !startsWith(github.ref, 'refs/tags/v') }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Put back the git branch into git (Earthly uses it for tagging) | ||
run: | | ||
branch="" | ||
if [ -n "$GITHUB_HEAD_REF" ]; then | ||
branch="$GITHUB_HEAD_REF" | ||
else | ||
branch="${GITHUB_REF##*/}" | ||
fi | ||
git checkout -b "$branch" || true | ||
- name: Download Earthly | ||
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.8/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" | ||
- name: Validate PR | ||
run: | | ||
earthly --ci +validate-pr | ||
release: | ||
permissions: | ||
contents: write | ||
# needs: test | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Put back the git branch into git (Earthly uses it for tagging) | ||
run: | | ||
branch="" | ||
if [ -n "$GITHUB_HEAD_REF" ]; then | ||
branch="$GITHUB_HEAD_REF" | ||
else | ||
branch="${GITHUB_REF##*/}" | ||
fi | ||
git checkout -b "$branch" || true | ||
- name: Download Earthly | ||
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.8/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" | ||
- name: Build and create release | ||
run: | | ||
earthly --ci +release \ | ||
--RELEASE_VERSION=${GITHUB_REF:10} \ | ||
--GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
gokv | ||
bin | ||
build | ||
.arg | ||
.env |
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 |
---|---|---|
@@ -1,12 +1,74 @@ | ||
VERSION 0.6 | ||
VERSION 0.7 | ||
|
||
FROM golang:1.18-bullseye | ||
|
||
build: | ||
validate-pr: | ||
WORKDIR /app | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
COPY . . | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o ./build/frp-port-keeper ./main.go | ||
|
||
multi-build: | ||
ARG --required RELEASE_VERSION | ||
ENV PLATFORMS="darwin/amd64 darwin/arm64 windows/amd64 linux/amd64 linux/arm64" | ||
ENV VERSION_INJECT="github.com/librepod/frp-port-keeper/main.Version" | ||
ENV OUTPUT_PATH_FORMAT="./build/${RELEASE_VERSION}/{{.OS}}/{{.Arch}}/frp-port-keeper" | ||
|
||
WORKDIR /app | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
COPY . . | ||
RUN go install github.com/mitchellh/[email protected] \ | ||
&& gox -osarch="${PLATFORMS}" -ldflags "-X ${VERSION_INJECT}=${RELEASE_VERSION}" -output "${OUTPUT_PATH_FORMAT}" | ||
|
||
SAVE ARTIFACT build /build AS LOCAL ./build | ||
|
||
release: | ||
FROM +multi-build | ||
|
||
ARG --required GITHUB_TOKEN | ||
ARG --required RELEASE_VERSION | ||
ARG OUT_BASE="./build/${RELEASE_VERSION}" | ||
|
||
# Install gh-cli | ||
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ | ||
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ | ||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | ||
&& apt-get update && apt-get install gh jq -y \ | ||
&& gh --version | ||
|
||
# Generate release notes | ||
RUN gh api -X POST 'repos/librepod/frp-port-keeper/releases/generate-notes' \ | ||
-F commitish=${RELEASE_VERSION} \ | ||
-F tag_name=${RELEASE_VERSION} \ | ||
> tmp-release-notes.json \ | ||
&& cat ./tmp-release-notes.json | jq | ||
|
||
# Gzip the bins | ||
RUN tar -czvf "${OUT_BASE}/darwin/amd64/frp-port-keeper_darwin_amd64.tar.gz" -C "${OUT_BASE}/darwin/amd64" frp-port-keeper \ | ||
&& tar -czvf "${OUT_BASE}/darwin/arm64/frp-port-keeper_darwin_arm64.tar.gz" -C "${OUT_BASE}/darwin/arm64" frp-port-keeper \ | ||
&& tar -czvf "${OUT_BASE}/windows/amd64/frp-port-keeper_windows_amd64.tar.gz" -C "${OUT_BASE}/windows/amd64" frp-port-keeper.exe \ | ||
&& tar -czvf "${OUT_BASE}/linux/amd64/frp-port-keeper_linux_amd64.tar.gz" -C "${OUT_BASE}/linux/amd64" frp-port-keeper \ | ||
&& tar -czvf "${OUT_BASE}/linux/arm64/frp-port-keeper_linux_arm64.tar.gz" -C "${OUT_BASE}/linux/arm64" frp-port-keeper | ||
|
||
# Create release | ||
RUN jq -r .body tmp-release-notes.json > tmp-release-notes.md \ | ||
&& gh release create ${RELEASE_VERSION} \ | ||
--title "$(jq -r .name tmp-release-notes.json)" \ | ||
--notes-file tmp-release-notes.md \ | ||
--verify-tag \ | ||
--draft \ | ||
"${OUT_BASE}/darwin/amd64/frp-port-keeper_darwin_amd64.tar.gz#frp-port-keeper_osx_amd64" \ | ||
"${OUT_BASE}/darwin/arm64/frp-port-keeper_darwin_arm64.tar.gz#frp-port-keeper_osx_arm64" \ | ||
"${OUT_BASE}/windows/amd64/frp-port-keeper_windows_amd64.tar.gz#frp-port-keeper_windows_amd64" \ | ||
"${OUT_BASE}/linux/amd64/frp-port-keeper_linux_amd64.tar.gz#frp-port-keeper_linux_amd64" \ | ||
"${OUT_BASE}/linux/arm64/frp-port-keeper_linux_arm64.tar.gz#frp-port-keeper_linux_arm64" | ||
|
||
SAVE ARTIFACT build /build AS LOCAL ./build | ||
|
||
validate-mr: | ||
# Smoke test the application | ||
# TODO: set proper validation | ||
BUILD +build | ||
|