diff --git a/.github/configuration/codeql-config.yml b/.github/configuration/codeql-config.yml new file mode 100644 index 0000000..e4ed756 --- /dev/null +++ b/.github/configuration/codeql-config.yml @@ -0,0 +1,4 @@ +name: "Code QL Configuration" + +paths: + - ./src \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9d3266f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/src" # Location of package manifests + schedule: + interval: "weekly" + open-pull-requests-limit: 50 \ No newline at end of file diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 0000000..8275b59 --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,76 @@ +name: 'Build Docker Image' + +on: + push: + branches: + - master + paths: + - "Dockerfile" + - "src/**" + - ".github/workflows/**" + + # Allows you to run this workflow manually from the Actions tab. We can override the branch, image name, and docker registry. + workflow_dispatch: + inputs: + ref: + description: 'Ref' + required: false + default: '' + image: + description: 'Image Name' + required: true + default: 'mfdlabs/ns1-github-comparator' + registry: + description: 'Docker Registry' + required: true + default: 'docker.io' + +jobs: + build: + if: "!contains(github.event.head_commit.message, '[SKIP IMAGE]')" + runs-on: ubuntu-latest + + # If DOCKER_REGISTRY is not set, default to docker.io + env: + DOCKER_REGISTRY: ${{ github.event.inputs.registry || secrets.DOCKER_REGISTRY || 'docker.io' }} + IMAGE_NAME: ${{ github.event.inputs.image || secrets.IMAGE_NAME || 'mfdlabs/ns1-github-comparator' }} + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + + # Pushes 2 identical images to the registry, one with the tag latest and one with the version from git-ref + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.ref || github.ref }} + + # Error if IMAGE_NAME is not set + - name: Check IMAGE_NAME + run: | + if [ -z "$IMAGE_NAME" ]; then + echo "IMAGE_NAME is not set" + exit 1 + fi + + # Error if DOCKER_USERNAME is not set + - name: Check DOCKER_USERNAME + run: | + if [ -z "$DOCKER_USERNAME" ]; then + echo "DOCKER_USERNAME is not set" + exit 1 + fi + + # Error if DOCKER_PASSWORD is not set + - name: Check DOCKER_PASSWORD + run: | + if [ -z "$DOCKER_PASSWORD" ]; then + echo "DOCKER_PASSWORD is not set" + exit 1 + fi + + # Login to the registry + - name: Login to registry + run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login ${{ env.DOCKER_REGISTRY }} -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + + # Push the image to the registry + - name: Build & Push the image + run: make build-docker IMAGE_NAME=${{ env.IMAGE_NAME }} CI=true \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..95cbbf6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,57 @@ +name: Go Build + +on: + push: + branches: + - "master" + paths: + - "src/**" + - ".github/workflows/**" + pull_request: + paths: + - "src/**" + - ".github/workflows/**" + +jobs: + lint: + name: Go lint + if: "!contains(toJSON(github.event.commits.*.message), '[SKIP BUILD]')" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup the Golang environment with version 1.20.x + uses: actions/setup-go@v2 + with: + go-version: 1.20.x + + - name: Run lint + working-directory: ./src + run: go mod tidy && go mod vendor && go vet ./... + + build: + name: Build + if: "!contains(toJSON(github.event.commits.*.message), '[SKIP BUILD]')" + needs: lint + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + os: ["linux", "darwin", "windows"] + arch: ["x86", "x64", "arm", "arm64"] + config: ["debug", "release"] + + steps: + - name: Checkout repository. + uses: actions/checkout@v2 + + - name: Setup the Golang environment with version 1.20.x + uses: actions/setup-go@v2 + with: + go-version: 1.20.x + + - name: Run the build-- make target + run: make build-${{ matrix.config }}-${{ matrix.arch }} GOOS=${{ matrix.os }} + \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..7a70d38 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,29 @@ +name: CodeQL Analysis + +on: + push: + branches: + - "master" + pull_request: + branches: + - "master" + +jobs: + codeql: + if: "!contains(toJSON(github.event.commits.*.message), '[SKIP ANALYSIS]')" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: "go" + config-file: "./.github/configuration/codeql-config.yml" + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c29ff20 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Go Test + +on: + push: + branches: + - "master" + paths: + - "src/**" + - ".github/workflows/**" + pull_request: + paths: + - "src/**" + - ".github/workflows/**" + +jobs: + test: + name: Go Test + if: "!contains(toJSON(github.event.commits.*.message), '[SKIP TEST]')" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup the Golang environment with version 1.20.x + uses: actions/setup-go@v2 + with: + go-version: 1.20.x + + - name: Run Test + run: make test