Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Actions for Testing and Building #88

Merged
merged 11 commits into from
Dec 20, 2023
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ branches:
protection:
required_status_checks:
strict: true
contexts: ["continuous-integration/jenkins/pr-merge"]
contexts: ['Test']
enforce_admins: true
restrictions:
apps: []
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build

on:
push:
branches:
- main

permissions:
contents: write

jobs:
Build:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get Latest Version
id: latest
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
- name: Calculate Next Version
id: calculate
if: "contains(steps.latest.outputs.release, '.')"
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
majorList: break,release
minorList: feature,new,add,update
patchAll: true
- name: Determine Next Version
id: version
uses: haya14busa/action-cond@v1
with:
cond: contains(steps.latest.outputs.release, '.')
if_true: ${{ steps.calculate.outputs.next }}
if_false: v0.0.1
- name: Update Version in Files
if: "contains(steps.latest.outputs.release, '.')"
uses: datamonsters/replace-action@v2
with:
files: 'journal.go,web/app/package.json'
replacements: '${{ steps.latest.output.release }}=${{ steps.version.outputs.value }}'
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Update version to ${{ steps.version.outputs.value }}
- name: Docker Login
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
run: |
docker build -t ghcr.io/jamiefdhurst/journal:latest .
docker tag ghcr.io/jamiefdhurst/journal:latest ghcr.io/jamiefdhurst/journal:${{ steps.version.outputs.value }}
docker push ghcr.io/jamiefdhurst/journal:latest
docker push ghcr.io/jamiefdhurst/journal:${{ steps.version.outputs.value }}
- name: Create Release
uses: ncipollo/[email protected]
with:
allowUpdates: true
draft: false
makeLatest: true
tag: ${{ steps.version.outputs.value }}
name: Release ${{ steps.version.outputs.value }}
82 changes: 82 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test

on:
push:
branches:
- '*'
- '!main'
pull_request: {}

permissions:
contents: read
issues: read
checks: write
pull-requests: write

env:
GOPATH: /home/runner/work/journal/journal/go
J_ARTICLES_PER_PAGE: ''
J_DB_PATH: ''
J_GIPHY_API_KEY: ''
J_PORT: ''
J_TITLE: ''

jobs:
Test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
path: go/src/github.com/jamiefdhurst/journal
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
cache-dependency-path: go/src/github.com/jamiefdhurst/journal/go.sum
- name: Install Dependencies
working-directory: go/src/github.com/jamiefdhurst/journal
run: |
go get -v ./...
go install -v ./...
go install github.com/tebeka/go2xunit@latest
go install github.com/axw/gocov/gocov@latest
go install github.com/AlekSi/gocov-xml@latest
- name: Test
working-directory: go/src/github.com/jamiefdhurst/journal
run: make test
- name: Upload Test Results
uses: actions/upload-artifact@v3
with:
name: tests
path: go/src/github.com/jamiefdhurst/journal/tests.xml
- name: Upload Coverage
uses: actions/upload-artifact@v3
with:
name: coverage
path: go/src/github.com/jamiefdhurst/journal/coverage.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
action_fail: true
files: |
go/src/github.com/jamiefdhurst/journal/tests.xml
- name: Publush Code Coverage
uses: irongut/[email protected]
with:
filename: go/src/github.com/jamiefdhurst/journal/coverage.xml
badge: false
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '80 90'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ node_modules
test/data/test.db
.vscode
.DS_Store
.history
55 changes: 0 additions & 55 deletions Jenkinsfile

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: test

test:
@2>&1 go test -coverprofile=cover.out -coverpkg=./internal/...,./pkg/... -v ./... | go2xunit
@gocover-cobertura < cover.out > coverage.xml
@2>&1 go test -coverprofile=cover.out -coverpkg=./internal/...,./pkg/... -v ./... | go2xunit > tests.xml
@gocov convert cover.out | gocov-xml > coverage.xml