Skip to content

Commit

Permalink
feat: add context support
Browse files Browse the repository at this point in the history
BREAKING CHANGE: now all fsm interfaces contains context.Context as first argument
  • Loading branch information
MrEhbr committed Jan 5, 2023
1 parent 074ef96 commit 08735bc
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 84 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
@@ -0,0 +1,67 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
schedule:
- cron: "33 8 * * 3"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: ["go"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v3.1.0

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Expand Up @@ -34,16 +34,16 @@ jobs:
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and Push to Docker Hub
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
if: github.event_name == 'release' || github.event_name == 'push'
with:
context: .
Expand Down
104 changes: 74 additions & 30 deletions .github/workflows/ci.yml → .github/workflows/go.yml
@@ -1,35 +1,82 @@
name: CI
name: Go
on:
push:
tags:
- v*
branches:
- master
- main
paths:
- "**.go"
- ".goreleaser.yml"
- ".golangci.yml"
- ".dockerignore"
- "Makefile"
- "rules.mk"
- "go.*"
- ".github/workflows/go.yml"
pull_request:
paths:
- "**.go"
- ".goreleaser.yml"
- ".golangci.yml"
- ".dockerignore"
- "Makefile"
- "rules.mk"
- "go.*"
- ".github/workflows/go.yml"

jobs:
goreleaser-dryrun:
strategy:
matrix:
golang: [1.17.x]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.golang }}
- name: Cache Go modules
uses: actions/cache@v3.0.11
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1-
- name: Run GoReleaser (Dry Run)
uses: goreleaser/goreleaser-action@v3.2.0
with:
version: latest
args: release --rm-dist --snapshot --skip-publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
strategy:
matrix:
golangci_lint: [v1.50]
steps:
- uses: actions/checkout@v2
- name: lint
uses: golangci/golangci-lint-action@v2
- uses: actions/checkout@v3.1.0
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.0
with:
version: v1.44
args: --timeout=2m
version: ${{ matrix.golangci_lint }}
github-token: ${{ secrets.GITHUB_TOKEN }}
args: --timeout=2m
only-new-issues: false
working-directory: .
tests-on-windows:
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
runs-on: windows-latest
strategy:
matrix:
golang:
- 1.17.x
golang: [1.17.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.golang }}
- name: Run tests on Windows
Expand All @@ -40,23 +87,21 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
golang:
- 1.17.x
golang: [1.17.x]
env:
OS: macos-latest
GOLANG: ${{ matrix.golang }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.golang }}
- uses: actions/cache@v1
- uses: actions/cache@v3.0.11
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.golang }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.golang }}-
key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1-
- name: Compile the project
run: make go.install
- name: Run tests on Unix-like operating systems
Expand All @@ -67,9 +112,9 @@ jobs:
git --no-pager diff go.mod go.sum
git --no-pager diff --quiet go.mod go.sum
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3.1.1
with:
#token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
flags: unittests
env_vars: OS,GOLANG
Expand All @@ -86,19 +131,18 @@ jobs:
OS: ubuntu-latest
GOLANG: ${{ matrix.golang }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.golang }}
- uses: actions/cache@v1
- uses: actions/cache@v3.0.11
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.golang }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.golang }}-
- name: Build the project
run: make go.build
key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1-
- name: Compile the project
run: make go.install
- name: Check go.mod and go.sum
run: |
go mod tidy -v
Expand All @@ -107,7 +151,7 @@ jobs:
- name: Run tests on Unix-like operating systems
run: make unittest
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/pr.yml
@@ -1,8 +1,9 @@
name: PR

on:
#pull_request_target:
pull_request:
branches: [main]
branches: [master, main]
issue_comment:
types: [edited]

Expand All @@ -11,10 +12,10 @@ jobs:
name: Release-Notes Preview
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0
- run: |
git fetch --prune --unshallow --tags
- uses: snyk/release-notes-preview@v1.6.1
- uses: snyk/release-notes-preview@v1.6.2
with:
releaseBranch: main
env:
Expand All @@ -25,7 +26,7 @@ jobs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0
with:
depth: 1
- uses: K-Phoen/action-misspell@master
Expand Down
21 changes: 12 additions & 9 deletions .github/workflows/release.yml
Expand Up @@ -2,38 +2,41 @@ name: Release
on:
push:
branches:
- master
- main

jobs:
release:
name: releaser
runs-on: ubuntu-latest
strategy:
matrix:
golang: [1.17.x]
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v3.1.0
- name: Unshallow
run: git fetch --prune --unshallow
- name: Run Semantic Release
id: semantic
uses: codfish/semantic-release-action@v1
uses: codfish/semantic-release-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
if: steps.semantic.outputs.new-release-published == 'true'
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.17.x
go-version: ${{ matrix.golang }}
- name: Cache Go modules
if: steps.semantic.outputs.new-release-published == 'true'
uses: actions/cache@v1
uses: actions/cache@v3.0.11
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
key: ${{ runner.os }}-go-${{ matrix.golang }}-v1-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-${{ matrix.golang }}-v1-
- name: Run GoReleaser
if: steps.semantic.outputs.new-release-published == 'true'
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v3.2.0
with:
version: latest
args: release --rm-dist
Expand Down
3 changes: 1 addition & 2 deletions cmd/go-fsm/commands/actions_doc.go
Expand Up @@ -3,7 +3,6 @@ package commands
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -82,7 +81,7 @@ func ActionDocGenerate(trFile, output string) error {
}

var source []byte
source, _ = ioutil.ReadFile(output)
source, _ = os.ReadFile(output)

md := goldmark.New(
goldmark.WithExtensions(extension.GFM),
Expand Down
7 changes: 3 additions & 4 deletions cmd/go-fsm/commands/actions_gen.go
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"text/template"
Expand Down Expand Up @@ -61,7 +60,7 @@ var ActionsGenCommand = &cli.Command{
}
}

tpl, err := ioutil.ReadFile(c.String("template"))
tpl, err := os.ReadFile(c.String("template"))
if err != nil {
return cli.Exit(err, 1)
}
Expand Down Expand Up @@ -117,7 +116,7 @@ func actionsGenerate(trFile, outputDir, tpl string) error {
return fmt.Errorf("failed to format generated code: %w", err)
}

if err := ioutil.WriteFile(fileName, processedSource, 0o644); err != nil {
if err := os.WriteFile(fileName, processedSource, 0o644); err != nil {
return fmt.Errorf("failed to write file %q: %w", fileName, err)
}
}
Expand All @@ -142,7 +141,7 @@ func transitionsFromFile(name string) (fsm.Transitions, error) {
decoder = yaml.Unmarshal
}

data, err := ioutil.ReadFile(name)
data, err := os.ReadFile(name)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 08735bc

Please sign in to comment.