Skip to content

Commit fc3ae4b

Browse files
committed
refactor: update code structure
1 parent 7edae74 commit fc3ae4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+682
-753
lines changed

.air.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ tmp_dir = "tmp"
77

88
[build]
99
# Just plain old shell command. You could use `make` as well.
10-
cmd = "go build -tags dev -o ./tmp/main ."
10+
cmd = "go build -o ./tmp/main ."
1111
# Binary file yields from `cmd`.
1212
bin = "tmp/main"
1313
# Customize binary.
1414
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main server -vv"
1515
# Watch these filename extensions.
1616
include_ext = ["go", "tpl", "tmpl", "html", "vue", "js", "css", "woff", "ttf"]
1717
# Ignore these filename extensions or directories.
18-
exclude_dir = ["tmp", "libs", "vendor", "view"]
18+
exclude_dir = ["tmp", "libs", "vendor", "view", "web/static"]
1919
# Watch these directories if you specified.
2020
include_dir = []
2121
# Exclude files.

.github/workflows/beta.yml

Lines changed: 0 additions & 131 deletions
This file was deleted.

.github/workflows/release-nightly.yml

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
name: "🚀 Release Nightly"
2+
3+
# on events
4+
on:
5+
schedule:
6+
- cron: '0 0 * * *' # runs daily at 00:00
7+
workflow_dispatch:
8+
push:
9+
branches: [main, master, release/v*]
10+
11+
# jobs
12+
jobs:
13+
check:
14+
name: Check has new commits today
15+
permissions:
16+
contents: write
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout the repository
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
- name: Get new commits
24+
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_OUTPUT
25+
26+
build:
27+
name: Generate cross-platform builds
28+
if: ${{needs.check.outputs.NEW_COMMIT_COUNT > 0}}
29+
permissions:
30+
contents: write
31+
strategy:
32+
matrix:
33+
go_version: [1.21.x]
34+
runs-on: ubuntu-latest
35+
outputs:
36+
VERSION: ${{steps.vars.outputs.VERSION}}
37+
BUILDDATE: ${{steps.vars.outputs.BUILDDATE}}
38+
COMMIT: ${{steps.vars.outputs.COMMIT}}
39+
APP_NAME: ${{steps.vars.outputs.APP_NAME}}
40+
PUSH_DOCKERHUB: ${{steps.vars.outputs.PUSH_DOCKERHUB}}
41+
steps:
42+
# step 1: checkout repository code
43+
- name: Checkout the repository
44+
uses: actions/checkout@v3
45+
with:
46+
fetch-depth: 0
47+
48+
# step 2: setup build envirement
49+
- uses: actions/setup-go@v3
50+
with:
51+
go-version: ${{ matrix.go_version }}
52+
- uses: actions/setup-node@v2
53+
with:
54+
node-version: "16"
55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v2
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v2
59+
60+
# step 3: set workflow variables
61+
- id: metadata
62+
uses: ahmadnassri/action-metadata@v2
63+
- name: Initialize workflow environments variables
64+
id: vars
65+
run: |
66+
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT
67+
echo "BUILDDATE=$(date '+%F-%T')" >> $GITHUB_OUTPUT
68+
echo "COMMIT=$(git rev-parse --verify HEAD)" >> $GITHUB_OUTPUT
69+
echo "APP_NAME=${{ steps.metadata.outputs.repository_name }}" >> $GITHUB_OUTPUT
70+
echo "REPO=$(echo 'github.com/${{ github.repository }}')" >> $GITHUB_OUTPUT
71+
echo "BRANCH=${{ steps.metadata.outputs.repository_default_branch }}" >> $GITHUB_OUTPUT
72+
73+
if [ ! -z $DOCKER_TOKEN ]; then echo "PUSH_DOCKERHUB=1" >> $GITHUB_OUTPUT; fi
74+
env:
75+
DOCKER_TOKEN: "${{ secrets.DOCKER_TOKEN }}"
76+
77+
# step 4: generate build files
78+
- name: build frontend
79+
run: cd ./view && npm install && npm run build
80+
- name: Generate build files
81+
uses: crazy-max/ghaction-xgo@v2
82+
env:
83+
CGO_ENABLED: "0"
84+
with:
85+
xgo_version: latest
86+
go_version: ${{ matrix.go_version }}
87+
dest: build
88+
prefix: ${{steps.vars.outputs.APP_NAME}}
89+
targets: windows/386,windows/amd64,linux/386,linux/amd64,darwin/386,darwin/amd64,linux/386,linux/arm64
90+
v: true
91+
x: false
92+
ldflags: -w -s -X ${{steps.vars.outputs.REPO}}/internal/app/build.Version=${{steps.vars.outputs.VERSION}} -X ${{steps.vars.outputs.REPO}}/internal/app/build.BuildDate=${{steps.vars.outputs.BUILDDATE}} -X ${{steps.vars.outputs.REPO}}/internal/app/build.Commit=${{steps.vars.outputs.COMMIT}} -X ${{steps.vars.outputs.REPO}}/internal/mode.Mode=production
93+
94+
# step 5: Upload binary to artifact
95+
- name: Upload artifact
96+
uses: actions/upload-artifact@v3
97+
with:
98+
name: ${{steps.vars.outputs.APP_NAME}}
99+
path: build
100+
retention-days: 1
101+
102+
# step 6: Generate Changelog
103+
- name: Generate Changelog
104+
id: changelog
105+
uses: bitxeno/changelogithub-action@v1
106+
with:
107+
token: ${{ secrets.GITHUB_TOKEN }}
108+
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
109+
# output-file: ./docs/CHANGELOG.md
110+
types: |
111+
feat
112+
fix
113+
perf
114+
refactor
115+
chore
116+
docs
117+
# build
118+
# test
119+
# style
120+
# ci
121+
# - name: Git commit changelog
122+
# uses: EndBug/add-and-commit@v9
123+
# with:
124+
# default_author: github_actions
125+
# add: "docs/"
126+
# message: "docs: release notes for ${{ github.ref_name }}"
127+
# push: "origin HEAD:${{ steps.vars.outputs.BRANCH }}"
128+
129+
# step 7: Upload binary to GitHub Release
130+
- name: Compress build files
131+
run: cd ./build && for i in *; do tar -czf $i.tar.gz $i; done && cd ..
132+
- name: Upload binary to GitHub Release
133+
uses: softprops/action-gh-release@v2
134+
if: "startsWith(github.ref, 'refs/tags/')"
135+
with:
136+
files: |
137+
./build/*.tar.gz
138+
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
139+
body: ${{ steps.changelog.outputs.changelog }}
140+
fail_on_unmatched_files: true
141+
142+
dockerhub:
143+
name: Push to DockerHub
144+
if: ${{needs.build.outputs.PUSH_DOCKERHUB}}
145+
needs: [build]
146+
permissions:
147+
contents: read
148+
packages: write
149+
runs-on: ubuntu-latest
150+
steps:
151+
- name: Checkout the repository
152+
uses: actions/checkout@v3
153+
- name: Download artifact
154+
uses: actions/download-artifact@v3
155+
with:
156+
name: ${{needs.build.outputs.APP_NAME}}
157+
path: build
158+
- name: Login to DockerHub
159+
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN }}
160+
uses: docker/login-action@v2
161+
with:
162+
username: ${{ secrets.DOCKER_USERNAME }}
163+
password: ${{ secrets.DOCKER_TOKEN }}
164+
- name: Extract metadata (tags, labels) for Docker
165+
id: meta
166+
uses: docker/metadata-action@v5
167+
with:
168+
images: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
169+
- name: Build and push Docker images to DockerHub
170+
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN }}
171+
uses:docker/build-push-action@v5
172+
with:
173+
context: .
174+
push: true
175+
platforms: linux/amd64,linux/arm64
176+
tags: ${{ steps.meta.outputs.tags }}
177+
labels: ${{ steps.meta.outputs.labels }}
178+
build-args: |
179+
APP_NAME=${{needs.build.outputs.APP_NAME}}
180+
VERSION=${{needs.build.outputs.VERSION}}
181+
BUILDDATE=${{needs.build.outputs.BUILDDATE}}
182+
COMMIT=${{needs.build.outputs.COMMIT}}
183+
184+
ghcr:
185+
name: Push to GitHub Container Registry
186+
needs: [build]
187+
permissions:
188+
contents: read
189+
packages: write
190+
runs-on: ubuntu-latest
191+
steps:
192+
- name: Checkout the repository
193+
uses: actions/checkout@v3
194+
- name: Download artifact
195+
uses: actions/download-artifact@v3
196+
with:
197+
name: ${{needs.build.outputs.APP_NAME}}
198+
path: build
199+
- name: Display structure of downloaded files
200+
run: ls -R
201+
working-directory: build
202+
- name: Login to GitHub Container Registry
203+
uses: docker/login-action@v2
204+
with:
205+
registry: ghcr.io
206+
username: ${{ github.actor }}
207+
password: ${{ secrets.GITHUB_TOKEN }}
208+
- name: Extract metadata (tags, labels) for Docker
209+
id: meta
210+
uses: docker/metadata-action@v5
211+
with:
212+
images: ghcr.io/${{ github.repository }}
213+
- name: Build and push Docker images to ghci
214+
uses: docker/build-push-action@v5
215+
with:
216+
context: .
217+
push: true
218+
provenance: false
219+
platforms: linux/amd64,linux/arm64
220+
tags: ${{ steps.meta.outputs.tags }}
221+
labels: ${{ steps.meta.outputs.labels }}
222+
build-args: |
223+
APP_NAME=${{needs.build.outputs.APP_NAME}}
224+
VERSION=${{needs.build.outputs.VERSION}}
225+
BUILDDATE=${{needs.build.outputs.BUILDDATE}}
226+
COMMIT=${{needs.build.outputs.COMMIT}}
227+
228+
clean:
229+
name: Delete temp artifacts
230+
# ignore dockerhub job skipped
231+
if: always() && (needs.dockerhub.result == 'success' || needs.dockerhub.result == 'skipped') && (needs.ghcr.result == 'success')
232+
needs: [build, dockerhub, ghcr]
233+
permissions:
234+
contents: write
235+
runs-on: ubuntu-latest
236+
steps:
237+
- uses: geekyeggo/delete-artifact@v2
238+
with:
239+
name: ${{needs.build.outputs.APP_NAME}}
240+
failOnError: false

0 commit comments

Comments
 (0)