Skip to content

feat(authorization): use github.com/Scalingo/go-plugins-helpers/sdk #15

feat(authorization): use github.com/Scalingo/go-plugins-helpers/sdk

feat(authorization): use github.com/Scalingo/go-plugins-helpers/sdk #15

Workflow file for this run

name: Unit tests and linters
on: [push]
# The list of permissions is explained on the GitHub doc:
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
# Write permissions is needed to create a new release
contents: write
# allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
env:
GO_ENV: test
PLUGIN_SPEC_DIR: /tmp
jobs:
linter-pull-request:
name: golangci-lint on a PR or from a tag
runs-on: ubuntu-22.04
if: github.ref != 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
# We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Get golangci-lint configuration file
run: wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
- name: Get master branch commit ID
id: new-from-rev
run: echo "NEW_FROM_REV=$( git rev-parse origin/master )" >> "$GITHUB_OUTPUT"
- name: "Execute golangci-lint on a pull request"
uses: golangci/golangci-lint-action@v6
with:
# The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
# We rather decided to use the suggestion from the FAQ (https://golangci-lint.run/usage/faq/#how-to-integrate-golangci-lint-into-large-project-with-thousands-of-issues) and use `--new-from-rev`
# only-new-issues: false
args: "--config=$(pwd)/.golangci.yml --new-from-rev=${{ steps.new-from-rev.outputs.NEW_FROM_REV }} --modules-download-mode=mod"
linter-master:
name: golangci-lint on master branch
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
# We need to define the fetch-depth to 2 so that we can get new offenses since HEAD~1
fetch-depth: 2
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: Get golangci-lint configuration file
run: wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml
- name: "Execute golangci-lint on the master branch"
uses: golangci/golangci-lint-action@v6
with:
# The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531).
# We rather decided to use the suggestion from the FAQ (https://golangci-lint.run/usage/faq/#how-to-integrate-golangci-lint-into-large-project-with-thousands-of-issues) and use `--new-from-rev`
# only-new-issues: false
args: "--config=$(pwd)/.golangci.yml --new-from-rev=HEAD~1"
tests:
name: Unit Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Test environment variables content
run: echo "$GO_ENV - $PLUGIN_SPEC_DIR"
- run: env
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
check-latest: true
- name: go mod vendor
run: go mod vendor
- name: Execute the tests
run: go test -race ./...