Skip to content

Commit

Permalink
Merge pull request #1 from abjrcode/ci-setup
Browse files Browse the repository at this point in the history
chore: test cicd pipeline
  • Loading branch information
abjrcode authored Oct 1, 2023
2 parents 9bdc5ea + f7d77a6 commit 6ee41f8
Show file tree
Hide file tree
Showing 22 changed files with 657 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.github
build/bin
frontend/node_modules
frontend/dist
build/windows/installer/tmp/MicrosoftEdgeWebview2Setup.exe
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
* text eol=lf
*.png binary
*.exe binary
*.ico binary
*.jpg binary
*.icns binary
*.dmg binary
88 changes: 88 additions & 0 deletions .github/workflows/build-darwin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Darwin Build

on:
workflow_call:
inputs:
GO_VERSION:
type: string
description: "Full Go version to use, e.g. 1.21.1"
required: true
NODE_VERSION:
type: string
description: "Node version to use, e.g. 18, 20 etc"
required: true
WAILS_VERSION:
type: string
description: "Wails version to use, e.g. v2.6.0"
required: true
outputs:
ReleaseTag:
value: ${{ jobs.Build.outputs.releaseTag }}

jobs:
Build:
runs-on: macos-latest

timeout-minutes: 10

outputs:
releaseTag: ${{ steps.calculateReleaseTag.outputs.releaseTag }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ inputs.GO_VERSION }}

- name: Install Wails
env:
WAILS_VERSION: ${{ inputs.WAILS_VERSION }}
run: |
go install github.com/wailsapp/wails/v2/cmd/wails@$WAILS_VERSION
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.NODE_VERSION }}

- name: Install Dependencies
run: |
brew install create-dmg
- name: Generate Build Timestamp ISO 8601
id: generateBuildTimestamp
run: |
BUILD_TIMESTAMP=$(date +'%Y-%m-%dT%H:%M:%S') && echo "BUILD_TIMESTAMP=$BUILD_TIMESTAMP" >> $GITHUB_OUTPUT
- name: Calculate Release Tag
id: calculateReleaseTag
run: |
RELEASE_TAG=$(git describe --tags) && echo $RELEASE_TAG && echo "releaseTag=$RELEASE_TAG" >> $GITHUB_OUTPUT
- name: Cache Node Modules
uses: actions/cache@v3
with:
key: node_modules-${{ hashFiles('./frontend/package-lock.json') }}
path: "./frontend/node_modules"

- name: Build Wails Application
env:
RELEASE_TAG: ${{ steps.calculateReleaseTag.outputs.releaseTag }}
BUILD_TIMESTAMP: ${{ steps.generateBuildTimestamp.outputs.BUILD_TIMESTAMP }}
COMMIT_SHA: ${{ github.sha }}
BUILD_LINK: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
go run mage.go build $RELEASE_TAG $BUILD_TIMESTAMP $COMMIT_SHA $BUILD_LINK
- name: Upload Build Arifacts
uses: actions/upload-artifact@v3
with:
name: release_bins
path: ./build/bin/*
if-no-files-found: error
retention-days: 1
92 changes: 92 additions & 0 deletions .github/workflows/build-linux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Linux Build

on:
workflow_call:
inputs:
GO_VERSION:
type: string
description: "Full Go version to use, e.g. 1.21.1"
required: true
NODE_VERSION:
type: string
description: "Node version to use, e.g. 18, 20 etc"
required: true
WAILS_VERSION:
type: string
description: "Wails version to use, e.g. v2.6.0"
required: true
outputs:
ReleaseTag:
value: ${{ jobs.Build.outputs.releaseTag }}

jobs:
Build:
runs-on: ubuntu-latest

timeout-minutes: 10

permissions:
contents: read
packages: write

outputs:
releaseTag: ${{ steps.calculateReleaseTag.outputs.releaseTag }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Generate Build Timestamp ISO 8601
id: generateBuildTimestamp
run: |
BUILD_TIMESTAMP=$(date +'%Y-%m-%dT%H:%M:%S') && echo "BUILD_TIMESTAMP=$BUILD_TIMESTAMP" >> $GITHUB_OUTPUT
- name: Calculate Release Tag
id: calculateReleaseTag
run: |
RELEASE_TAG=$(git describe --tags) && echo $RELEASE_TAG && echo "releaseTag=$RELEASE_TAG" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Wails Application
uses: docker/build-push-action@v4
env:
RELEASE_TAG: ${{ steps.calculateReleaseTag.outputs.releaseTag }}
with:
push: false
tags: |
swervo_builder
load: true
cache-from: |
type=registry,ref=ghcr.io/abjrcode/swervo/cache
cache-to: type=registry,ref=ghcr.io/abjrcode/swervo/cache,mode=max
build-args: |
GO_VERSION=${{ inputs.GO_VERSION }}
WAILS_VERSION=${{ inputs.WAILS_VERSION }}
NODE_MAJOR_VERSION=${{ inputs.NODE_VERSION }}
RELEASE_TAG=${{ env.RELEASE_TAG }}
BUILD_TIMESTAMP=${{ steps.generateBuildTimestamp.outputs.BUILD_TIMESTAMP }}
COMMIT_SHA=${{ github.sha }}
BUILD_LINK=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Extract Build Artifacts
run: |
docker run --rm -v $(pwd)/build/bin:/artifacts swervo_builder
- name: Upload Build Arifacts
uses: actions/upload-artifact@v3
with:
name: release_bins
path: ./build/bin/*
if-no-files-found: error
retention-days: 1
32 changes: 32 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Main

on:
push:
branches:
- main
workflow_dispatch:

concurrency:
group: swervo-main
cancel-in-progress: true

jobs:
LinuxCI:
uses: ./.github/workflows/build-linux.yaml

permissions:
contents: read
packages: write

with:
GO_VERSION: "1.21.1"
NODE_VERSION: "18"
WAILS_VERSION: "v2.6.0"

DarwinCI:
uses: ./.github/workflows/build-darwin.yaml

with:
GO_VERSION: "1.21.1"
NODE_VERSION: "18"
WAILS_VERSION: "v2.6.0"
41 changes: 41 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Pull Request

on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- main
workflow_dispatch:

concurrency:
group: swervo-pr-ci-${{ github.ref }}
cancel-in-progress: true

jobs:
LinuxCI:
if: ${{ !github.event.pull_request.draft }}

uses: ./.github/workflows/build-linux.yaml

permissions:
contents: read
packages: write

with:
GO_VERSION: "1.21.1"
NODE_VERSION: "18"
WAILS_VERSION: "v2.6.0"

DarwinCI:
if: ${{ !github.event.pull_request.draft }}

uses: ./.github/workflows/build-darwin.yaml

with:
GO_VERSION: "1.21.1"
NODE_VERSION: "18"
WAILS_VERSION: "v2.6.0"
60 changes: 60 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Release

on:
release:
types: [published]
workflow_dispatch:

concurrency:
group: swervo-release
cancel-in-progress: true

jobs:
LinuxCI:
uses: ./.github/workflows/build-linux.yaml

permissions:
contents: read
packages: write

with:
GO_VERSION: "1.21.1"
NODE_VERSION: "18"
WAILS_VERSION: "v2.6.0"

DarwinCI:
uses: ./.github/workflows/build-darwin.yaml

with:
GO_VERSION: "1.21.1"
NODE_VERSION: "18"
WAILS_VERSION: "v2.6.0"

Publish:
runs-on: ubuntu-latest
needs:
- LinuxCI
- DarwinCI
if: success()
permissions:
contents: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: release_bins
path: bins

- name: Upload Release Artifacts
uses: softprops/action-gh-release@v1
env:
RELEASE_TAG: ${{ needs.LinuxCI.outputs.releaseTag }}
with:
files: ./bins/*
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ env.RELEASE_TAG }}
generate_release_notes: false
append_body: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/bin
node_modules
frontend/dist
frontend/dist/
build/windows/installer/tmp/MicrosoftEdgeWebview2Setup.exe
seticon
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ARG GO_VERSION=1.21.1

FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} as builder

WORKDIR /usr/src/app

# Install Libgtk, webkit and NSIS
RUN apt -qq update && apt -qq install -y libgtk-3-dev libwebkit2gtk-4.0-dev nsis

ARG NODE_MAJOR_VERSION=18

# Install NodeJS
RUN apt-get -qq install -y ca-certificates curl gnupg && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR_VERSION.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt update && apt-get -qq install nodejs -y

# Install Wails
ARG WAILS_VERSION=v2.6.0
RUN go install github.com/wailsapp/wails/v2/cmd/wails@${WAILS_VERSION}

COPY go.mod go.sum ./

RUN go mod download

COPY . .

ARG RELEASE_TAG=v0.0.0-0-g000000
ARG BUILD_TIMESTAMP=NOW
ARG COMMIT_SHA=docker
ARG BUILD_LINK=http://docker.local
RUN go run mage.go build ${RELEASE_TAG} ${BUILD_TIMESTAMP} ${COMMIT_SHA} ${BUILD_LINK}


# I REALLY TRIED - ATTEMPT TO CROSS COMPILE BY USING GCC FOR AARCH64
# IT DID NOT WORK BECAUSE QEMU (SEEMINGLY USED BY WAILS) JUMPS FROM ONE ERROR TO ANOTHER

# - https://github.com/wailsapp/wails/issues/2833#issuecomment-1685684654
# - https://github.com/wailsapp/wails/issues/2060

#############################################################

FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}

COPY --from=builder /usr/src/app/build/bin /out

ENTRYPOINT [ "sh", "-c" ]
CMD [ "cp -r /out/. /artifacts/" ]
Loading

0 comments on commit 6ee41f8

Please sign in to comment.