Skip to content

Commit

Permalink
update github action
Browse files Browse the repository at this point in the history
  • Loading branch information
leokwsw committed Mar 22, 2024
1 parent 9a7ad44 commit cad79b0
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 42 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
46 changes: 46 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build

on:
push:
branches:
- '*'

env:
PLATFORMS: ${{ vars.PLATFORMS || 'linux/amd64,linux/arm64' }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}

- name: Set current datetime as env variable
env:
TZ: 'Asia/HongKong' # タイムゾーン指定
run: echo "CURRENT_DATETIME=$(date +'%Y-%m-%d-%H%M%S')" >> $GITHUB_ENV

# region setup and build
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'

- name: Install dependencies
run: go get .

- name: Build
run: go build -v .
# endregion

# region upload artifact
- uses: actions/upload-artifact@v4
with:
name: go-chatgpt-api-${{ env.CURRENT_DATETIME }}
path: go-chatgpt-api
# endregion
148 changes: 106 additions & 42 deletions .github/workflows/docker-push.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,129 @@
name: Docker build and push

on:
push:
branches:
- 'main'
# push:
# branches:
# - main
workflow_dispatch:
inputs:
branch:
description: "Branch to build from"
required: false
default: 'main'
image_tag:
description: "Image tag"
required: false
default: 'latest'

env:
PLATFORMS: ${{ vars.PLATFORMS || 'linux/amd64,linux/arm64' }}

jobs:
docker-build-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set current datetime as env variable
env:
TZ: 'Asia/HongKong' # タイムゾーン指定
run: echo "CURRENT_DATETIME=$(date +'%Y-%m-%d-%H%M%S')" >> $GITHUB_ENV

- name: Cache Docker layers
uses: actions/cache@v2
# region setup and build
- name: Setup Go
uses: actions/setup-go@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
go-version: '1.21.x'

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Install dependencies
run: go get .

- name: Build and push
uses: docker/build-push-action@v4
- name: Build
run: go build -v .
# endregion

# region upload artifact
- uses: actions/upload-artifact@v4
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ github.actor }}/go-chatgpt-api
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
name: go-chatgpt-api-${{ env.CURRENT_DATETIME }}
path: go-chatgpt-api
# endregion

- name: Log into ghcr
uses: docker/login-action@v2
if: ${{ vars.USE_GHCR == '1' }}
# region Release
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GT_TOKEN }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ env.CURRENT_DATETIME }}
release_name: Release ${{ env.CURRENT_DATETIME }}
draft: false
prerelease: false

- name: Build and push to ghcr
uses: docker/build-push-action@v4
if: ${{ vars.USE_GHCR == '1' }}
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GT_TOKEN }}
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: true
tags: ghcr.io/${{ github.actor }}/go-chatgpt-api
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./go-chatgpt-api
asset_name: go-chatgpt-api
asset_content_type: application/x-mach-binary
# endregion

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
#
# - name: Cache Docker layers
# uses: actions/cache@v2
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-
#
# - name: Login to DockerHub
# uses: docker/login-action@v2
# with:
# username: ${{ github.actor }}
# password: ${{ secrets.DOCKER_HUB_TOKEN }}
#
# - name: Build and push
# uses: docker/build-push-action@v4
# with:
# context: .
# platforms: ${{ env.PLATFORMS }}
# push: true
# tags: ${{ github.actor }}/go-chatgpt-api:${{ github.event.inputs.image_tag }}
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
#
# - name: Log into ghcr
# uses: docker/login-action@v2
# if: ${{ vars.USE_GHCR == '1' }}
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Build and push to ghcr
# uses: docker/build-push-action@v4
# if: ${{ vars.USE_GHCR == '1' }}
# with:
# context: .
# platforms: ${{ env.PLATFORMS }}
# push: true
# tags: ghcr.io/${{ github.actor }}/go-chatgpt-api:${{ github.event.inputs.image_tag }}
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
59 changes: 59 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release

on:
push:
branches:
- 'main'

env:
PLATFORMS: ${{ vars.PLATFORMS || 'linux/amd64,linux/arm64' }}

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}

- name: Set current datetime as env variable
env:
TZ: 'Asia/HongKong'
run: echo "CURRENT_DATETIME=$(date +'%Y-%m-%d-%H%M%S')" >> $GITHUB_ENV

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21.x'

- name: Install dependencies
run: go get .

- name: Build
run: go build -v .

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GT_TOKEN }}
with:
tag_name: release-${{ env.CURRENT_DATETIME }}
release_name: Release ${{ env.CURRENT_DATETIME }}
draft: false
prerelease: false

- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GT_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./go-chatgpt-api
asset_name: go-chatgpt-api
asset_content_type: application/x-mach-binary

0 comments on commit cad79b0

Please sign in to comment.