Skip to content

Commit

Permalink
updated workflows and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-alexander committed Sep 24, 2023
1 parent cc16cc0 commit f687f01
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 87 deletions.
149 changes: 149 additions & 0 deletions .github/workflows/go-queue_pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: go-queue_pull_request

on:
pull_request:
branches:
- main
paths:
- "./"
- ".github/workflows/go-queue_pull_request.yml"

env:
LINTER_VERSION: "v1.51.2"
GO_VERSION: "1.19"

jobs:
environment:
runs-on: ubuntu-latest
env:
GITHUB_SHA: ${{ github.event.pull_request.head.sha }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
steps:
- name: Get git target
run: |
git_target=`echo $GITHUB_BASE_REF | sed 's/refs\/heads\///'`
git_target=`echo $git_target | sed 's/refs\/tags\///'`
git_target=`echo $git_target| sed 's/refs\\///'`
echo $git_target
echo "git_target=$git_target" >> $GITHUB_ENV
- name: Get git source
run: |
git_source=`echo $GITHUB_HEAD_REF | sed 's/refs\/heads\///'`
git_source=`echo $git_source | sed 's/refs\/tags\///'`
git_source=`echo $git_source | sed 's/refs\\///'`
echo $git_source
echo "git_source=$git_source" >> $GITHUB_ENV
- name: Get git SHA
run: |
git_sha=`echo $GITHUB_SHA`
echo $git_sha
echo "git_sha=$git_sha" >> $GITHUB_ENV
- name: Checkout repository code (source)
uses: actions/checkout@v3
- name: Get source version
run: |
version_source=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
echo $version_source
echo "version_source=$version_source" >> $GITHUB_ENV
- name: Checkout repository code (target)
uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
- name: Get target version
run: |
version_target=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
echo $version_target
echo "version_target=$version_target" >> $GITHUB_ENV
- name: Generate build artifacts
run: |
mkdir -p /tmp
echo ${{ env.version_source }} >> /tmp/version_source
echo ${{ env.version_target }} >> /tmp/version_target
echo ${{ env.git_target }} >> /tmp/git_target
echo ${{ env.git_source }} >> /tmp/git_source
echo ${{ env.git_sha }} >> /tmp/git_sha
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
/tmp/version_source
/tmp/version_target
/tmp/git_target
/tmp/git_source
/tmp/git_sha
go_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.LINTER_VERSION }}
working-directory: .
args: --verbose

version_validate:
needs: [environment]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
path: /tmp
- name: Get environment
run: |
version_source=`cat /tmp/version_source`
echo "version_source=$version_source" >> $GITHUB_ENV
version_target=`cat /tmp/version_target`
echo "version_target=$version_target" >> $GITHUB_ENV
- name: Compare versions
run: |
echo "Comparing version \"${{ env.version_source }}\" to target version \"${{ env.version_target }}\""
if [ "${{ env.version_source }}" = "${{ env.version_target }}" ]; then
echo "versions are the same, versions must be different"
exit 1
fi
go_test:
needs: [go_lint, version_validate]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- name: Test go-queue/finite
continue-on-error: true
run: |
cd /home/runner/work/go-queue/go-queue/finite
go mod download
go test -v ./... -coverprofile /tmp/go-queue-finite.out > /tmp/go-queue-finite.log
- name: Test go-queue/infinite
continue-on-error: true
run: |
cd /home/runner/work/go-queue/go-queue/infinite
go mod download
go test -v ./... -coverprofile /tmp/go-queue-infinite.out > /tmp/go-queue-infinite.log
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: |
/tmp/go-queue-finite.log
/tmp/go-queue-infinite.log
/tmp/go-queue-finite.out
/tmp/go-queue-infinite.out
retention-days: 1
Original file line number Diff line number Diff line change
@@ -1,45 +1,69 @@
name: go-queue
name: go-queue_push

on:
push:
branches: ["main"]
pull_request:
release:
types: [published]
# branches:
# - main
paths:
- "./"
- ".github/workflows/go-queue_push.yml"

env:
LINTER_VERSION: "v1.51.2"
GO_VERSION: "1.19"

jobs:
version:
environment:
runs-on: ubuntu-latest
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
steps:
- name: Get git source
run: |
git_source=`echo $GITHUB_REF | sed 's/refs\/heads\///'`
git_source=`echo $git_source | sed 's/refs\/tags\///'`
git_source=`echo $git_source | sed 's/refs\\///'`
echo $git_source
echo "git_source=$git_source" >> $GITHUB_ENV
- name: Get git SHA
run: |
git_sha=`echo $GITHUB_SHA`
echo $git_sha
echo "git_sha=$git_sha" >> $GITHUB_ENV
- name: Checkout repository code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Get version
run: |
version=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
echo $version
echo "version=$version" >> $GITHUB_ENV
version_source=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
echo $version_source
echo "version_source=$version_source" >> $GITHUB_ENV
- name: Generate build artifacts
run: |
mkdir -p /tmp
echo ${{ env.version }} >> /tmp/version
echo ${{ env.version_source }} >> /tmp/version_source
echo ${{ env.git_source }} >> /tmp/git_source
echo ${{ env.git_sha }} >> /tmp/git_sha
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
/tmp/version
/tmp/version_source
/tmp/git_source
/tmp/git_sha
go_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.44.2
version: ${{ env.LINTER_VERSION }}
working-directory: .
args: --verbose

Expand Down Expand Up @@ -79,8 +103,7 @@ jobs:
retention-days: 1

git_push_tag:
if: github.ref == 'refs/heads/main'
needs: [go_test, version]
needs: [go_test, environment]
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -92,15 +115,15 @@ jobs:
path: /tmp
- name: Get version
run: |
version=`cat /tmp/version`
version=`cat /tmp/version_source`
echo "version=$version" >> $GITHUB_ENV
- name: Check out repository code
uses: actions/checkout@v2
with:
fetch-depth: "0"
- name: Push/Update go-queue version
uses: anothrNick/github-tag-action@1.36.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
CUSTOM_TAG: v${{ env.version }}
# - name: Push/Update go-queue version
# uses: anothrNick/github-tag-action@1.36.0
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# WITH_V: true
# CUSTOM_TAG: v${{ env.version }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this service will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.2.3] - 03/19/22

- Fixed the TestQueue test such that it used the example properly and would work even if the items returned was a slice of bytes

## [1.2.2] - 09/10/22

- Added "Must" functions that will block until success
Expand Down
8 changes: 4 additions & 4 deletions example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
)

//REFERENCE: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
// REFERENCE: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
func randomString(nLetters ...int) string {
letterRunes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
nLetter := 20
Expand All @@ -21,8 +21,8 @@ func randomString(nLetters ...int) string {
}

type Example struct {
Int int `json:"int,omitempty"`
Float float64 `json:"float,omitempty"`
Int int `json:"int,omitempty,string"`
Float float64 `json:"float,omitempty,string"`
String string `json:"string,omitempty"`
}

Expand Down Expand Up @@ -118,7 +118,7 @@ func ExampleFlush(queue Dequeuer) []*Example {
return ExampleConvertMultiple(queue.Flush())
}

//ExampleGenFloat64 will generate a random number of random float values if n is equal to 0
// ExampleGenFloat64 will generate a random number of random float values if n is equal to 0
// not to exceed the constant TestMaxExamples, if n is provided, it will generate that many items
func ExampleGenFloat64(sizes ...int) []*Example {
size := int(rand.Float64() * 100)
Expand Down
Loading

0 comments on commit f687f01

Please sign in to comment.