Skip to content

Commit

Permalink
refactor: update code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Jun 21, 2024
1 parent 7edae74 commit fc3ae4b
Show file tree
Hide file tree
Showing 60 changed files with 682 additions and 753 deletions.
4 changes: 2 additions & 2 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -tags dev -o ./tmp/main ."
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main server -vv"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "vue", "js", "css", "woff", "ttf"]
# Ignore these filename extensions or directories.
exclude_dir = ["tmp", "libs", "vendor", "view"]
exclude_dir = ["tmp", "libs", "vendor", "view", "web/static"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
Expand Down
131 changes: 0 additions & 131 deletions .github/workflows/beta.yml

This file was deleted.

240 changes: 240 additions & 0 deletions .github/workflows/release-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
name: "🚀 Release Nightly"

# on events
on:
schedule:
- cron: '0 0 * * *' # runs daily at 00:00
workflow_dispatch:
push:
branches: [main, master, release/v*]

# jobs
jobs:
check:
name: Check has new commits today
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get new commits
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_OUTPUT

build:
name: Generate cross-platform builds
if: ${{needs.check.outputs.NEW_COMMIT_COUNT > 0}}
permissions:
contents: write
strategy:
matrix:
go_version: [1.21.x]
runs-on: ubuntu-latest
outputs:
VERSION: ${{steps.vars.outputs.VERSION}}
BUILDDATE: ${{steps.vars.outputs.BUILDDATE}}
COMMIT: ${{steps.vars.outputs.COMMIT}}
APP_NAME: ${{steps.vars.outputs.APP_NAME}}
PUSH_DOCKERHUB: ${{steps.vars.outputs.PUSH_DOCKERHUB}}
steps:
# step 1: checkout repository code
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0

# step 2: setup build envirement
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go_version }}
- uses: actions/setup-node@v2
with:
node-version: "16"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# step 3: set workflow variables
- id: metadata
uses: ahmadnassri/action-metadata@v2
- name: Initialize workflow environments variables
id: vars
run: |
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "BUILDDATE=$(date '+%F-%T')" >> $GITHUB_OUTPUT
echo "COMMIT=$(git rev-parse --verify HEAD)" >> $GITHUB_OUTPUT
echo "APP_NAME=${{ steps.metadata.outputs.repository_name }}" >> $GITHUB_OUTPUT
echo "REPO=$(echo 'github.com/${{ github.repository }}')" >> $GITHUB_OUTPUT
echo "BRANCH=${{ steps.metadata.outputs.repository_default_branch }}" >> $GITHUB_OUTPUT
if [ ! -z $DOCKER_TOKEN ]; then echo "PUSH_DOCKERHUB=1" >> $GITHUB_OUTPUT; fi
env:
DOCKER_TOKEN: "${{ secrets.DOCKER_TOKEN }}"

# step 4: generate build files
- name: build frontend
run: cd ./view && npm install && npm run build
- name: Generate build files
uses: crazy-max/ghaction-xgo@v2
env:
CGO_ENABLED: "0"
with:
xgo_version: latest
go_version: ${{ matrix.go_version }}
dest: build
prefix: ${{steps.vars.outputs.APP_NAME}}
targets: windows/386,windows/amd64,linux/386,linux/amd64,darwin/386,darwin/amd64,linux/386,linux/arm64
v: true
x: false
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

# step 5: Upload binary to artifact
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{steps.vars.outputs.APP_NAME}}
path: build
retention-days: 1

# step 6: Generate Changelog
- name: Generate Changelog
id: changelog
uses: bitxeno/changelogithub-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
# output-file: ./docs/CHANGELOG.md
types: |
feat
fix
perf
refactor
chore
docs
# build
# test
# style
# ci
# - name: Git commit changelog
# uses: EndBug/add-and-commit@v9
# with:
# default_author: github_actions
# add: "docs/"
# message: "docs: release notes for ${{ github.ref_name }}"
# push: "origin HEAD:${{ steps.vars.outputs.BRANCH }}"

# step 7: Upload binary to GitHub Release
- name: Compress build files
run: cd ./build && for i in *; do tar -czf $i.tar.gz $i; done && cd ..
- name: Upload binary to GitHub Release
uses: softprops/action-gh-release@v2
if: "startsWith(github.ref, 'refs/tags/')"
with:
files: |
./build/*.tar.gz
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}
body: ${{ steps.changelog.outputs.changelog }}
fail_on_unmatched_files: true

dockerhub:
name: Push to DockerHub
if: ${{needs.build.outputs.PUSH_DOCKERHUB}}
needs: [build]
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{needs.build.outputs.APP_NAME}}
path: build
- name: Login to DockerHub
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
- name: Build and push Docker images to DockerHub
if: ${{ steps.vars.outputs.HAS_DOCKER_TOKEN }}
uses:docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_NAME=${{needs.build.outputs.APP_NAME}}
VERSION=${{needs.build.outputs.VERSION}}
BUILDDATE=${{needs.build.outputs.BUILDDATE}}
COMMIT=${{needs.build.outputs.COMMIT}}
ghcr:
name: Push to GitHub Container Registry
needs: [build]
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{needs.build.outputs.APP_NAME}}
path: build
- name: Display structure of downloaded files
run: ls -R
working-directory: build
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
- name: Build and push Docker images to ghci
uses: docker/build-push-action@v5
with:
context: .
push: true
provenance: false
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_NAME=${{needs.build.outputs.APP_NAME}}
VERSION=${{needs.build.outputs.VERSION}}
BUILDDATE=${{needs.build.outputs.BUILDDATE}}
COMMIT=${{needs.build.outputs.COMMIT}}
clean:
name: Delete temp artifacts
# ignore dockerhub job skipped
if: always() && (needs.dockerhub.result == 'success' || needs.dockerhub.result == 'skipped') && (needs.ghcr.result == 'success')
needs: [build, dockerhub, ghcr]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: geekyeggo/delete-artifact@v2
with:
name: ${{needs.build.outputs.APP_NAME}}
failOnError: false
Loading

0 comments on commit fc3ae4b

Please sign in to comment.