Merge pull request #3 from peterxcli/dependabot/go_modules/golang.org⦠#30
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
# This workflow will build a golang project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
name: ci | |
on: [push, pull_request] | |
env: | |
IMAGE_TAG: ${{ github.sha }} | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_USER: postgres | |
POSTGRES_DB: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5432:5432 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.20.1 | |
- name: Install Deps | |
run: sudo apt update && sudo apt install -y ca-certificates make git && make install | |
- name: Go Build | |
run: go build -v | |
- name: Test | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: postgres | |
POSTGRES_HOSTNAME: localhost | |
POSTGRES_PORT: 5432 | |
run: make test | |
build: | |
needs: [test] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build Image | |
uses: docker/build-push-action@v4 | |
with: | |
push: false | |
context: . | |
file: ./Dockerfile | |
tags: peter0814/linked-page:${{ github.sha }} | |
outputs: type=docker, dest=docker.tar | |
- name: cache | |
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3.1.1 | |
with: | |
name: docker.tar | |
path: docker.tar | |
swagger-ui: | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
needs: [test] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.20.1 | |
- name: Install Deps | |
run: sudo apt update && sudo apt install -y ca-certificates make git && make install | |
- name: Generate Swagger Json File | |
run: make swag | |
- name: Generate Swagger UI | |
uses: Legion2/swagger-ui-action@v1 | |
with: | |
output: swagger-ui | |
spec-file: docs/swagger.json | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: swagger-ui | |
# push: | |
# if: ${{ github.ref == 'refs/heads/release' }} | |
# needs : [build] | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - name: Set up QEMU | |
# uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0 | |
# - name: Set up Docker Buildx | |
# uses: docker/setup-buildx-action@v2 | |
# - name: docker login | |
# env: | |
# DOCKER_USER: ${{ secrets.DOCKER_USER }} | |
# DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
# run: | | |
# docker login -u $DOCKER_USER -p $DOCKER_PASSWORD | |
# - name: Download artifact | |
# uses: actions/download-artifact@v2 | |
# with: | |
# name: docker.tar | |
# path: ./ | |
# - name: Load Docker image | |
# run: | | |
# docker load --input docker.tar | |
# docker image ls -a | |
# - name: Docker Push | |
# run: docker push peter0814/basic-auth-gin:$IMAGE_TAG |