Skip to content

Commit

Permalink
chore: stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Aug 28, 2023
1 parent 6390a81 commit bb93d53
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 15 deletions.
2 changes: 2 additions & 0 deletions js/{{ cookiecutter.project_name }}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ repos:
rev: "v3.0.2"
hooks:
- id: prettier
stages:
- pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main
Expand All @@ -18,22 +16,31 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- uses: actions/setup-python@v4
- name: Set up JS
uses: actions/setup-node@v3
with:
python-version: 3.x

- name: Install dependencies
run: go install ./...
node-version: lts/*
cache: "npm"

- name: go-vet
run: go vet -v ./...
- name: Run dependencies
run: |
docker-compose up -d mysql
- uses: pre-commit/[email protected]
- name: Install and test
env:
DB_TYPE: mysql
DB_HOST: localhost
DB_USERNAME: app
DB_PASSWORD: password
DB_NAME: app
DB_PORT: "4000" # MySQL must not run on port 3306 - this conflicts with GitHub Actions
DB_MIGRATIONS_RUN: "true"
DB_SYNC: "false"
run: |
npm ci
npm run lint
npm test
npm run test:e2e
build:
runs-on: ubuntu-latest
Expand Down
127 changes: 127 additions & 0 deletions js/{{ cookiecutter.project_name }}/svelte/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Build
on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

- uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install dependencies
run: go install ./...

- name: go-vet
run: go vet -v ./...

- uses: pre-commit/[email protected]

build:
runs-on: ubuntu-latest
needs:
- test
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for goreleaser changelog to work correctly

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

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

- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v6
with:
strip_tag_prefix: v

- name: Generate Docker tag
id: docker
run: |
if [ "{{ '${{ steps.branch-name.outputs.is_tag }}' }}" = "true" ];
then
# Latest tag
IMG_NAME="ghcr.io/${GITHUB_REPOSITORY,,}:latest"
# Tag name (usually vX.Y.Z)
IMG_NAME="${IMG_NAME},ghcr.io/${GITHUB_REPOSITORY,,}:{{ '${{ steps.branch-name.outputs.tag }}' }}"
echo "image_name=${IMG_NAME}" >> "$GITHUB_OUTPUT"
echo "platforms=linux/amd64,linux/arm64,linux/arm/v7" >> "$GITHUB_OUTPUT"
else
# Use branch naming convention
TAG="branch-{{ '${{ steps.branch-name.outputs.current_branch }}' }}"
# Change "/" for "-"
TAG="${TAG//\//-}"
# Set to lowercase
TAG="${TAG,,}"
echo "image_name=ghcr.io/${GITHUB_REPOSITORY,,}:${TAG}" >> "$GITHUB_OUTPUT"
echo "platforms=linux/amd64" >> "$GITHUB_OUTPUT"
fi
if [ "{{ '${{ steps.branch-name.outputs.is_tag }}' }}" = "true" ];
then
echo "version={{ '${{ steps.branch-name.outputs.tag }}' }}" >> "$GITHUB_OUTPUT"
else
echo "version=development" >> "$GITHUB_OUTPUT"
fi
echo "container_tagged_image=ghcr.io/${GITHUB_REPOSITORY,,}:${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "commit_id=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "gitRepo=github.com/${GITHUB_REPOSITORY}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
build-args: |
GIT_COMMIT={{ '${{ steps.docker.outputs.commit_id }}' }}
GIT_REPO={{ '${{ steps.docker.outputs.gitRepo }}' }}
VERSION={{ '${{ steps.docker.outputs.version }}' }}
platforms: {{ '${{ steps.docker.outputs.platforms }}' }}
push: {{ '${{ github.ref == \'refs/heads/main\' }}' }}
tags: {{ '${{ steps.docker.outputs.image_name }},${{ steps.docker.outputs.container_tagged_image }}' }}

- name: Set up Go
if: steps.branch-name.outputs.is_tag == 'true'
uses: actions/setup-go@v3
with:
go-version: '>=1.20.0'

- name: Run GoReleaser
if: steps.branch-name.outputs.is_tag == 'true'
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GIT_REPO: {{ '${{ steps.docker.outputs.gitRepo }}' }}
GITHUB_TOKEN: {{ '${{ secrets.GITHUB_TOKEN }}' }}

0 comments on commit bb93d53

Please sign in to comment.