Skip to content

Commit

Permalink
feat: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunet committed Feb 7, 2022
0 parents commit 1d40148
Show file tree
Hide file tree
Showing 22 changed files with 2,324 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab
4 changes: 4 additions & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Semantic Commit bot: https://github.com/zeke/semantic-pull-requests

# Always validate the PR title, and ignore the commits
titleOnly: true
209 changes: 209 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
name: build

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
CGO_ENABLED: '0'
IMAGE_NAME: ghcr.io/maxbrunet/bitbucket-semantic-pull-requests

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest

timeout-minutes: 10

steps:
- name: Checkout repository
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
with:
fetch-depth: 2

- name: Set up Go
uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # renovate: tag=v2.1.5
with:
# renovate: datasource=golang-version depName=golang
go-version: 1.17.6

- name: Set up Go mod cache
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # renovate: tag=v2.1.7
with:
path: ~/go/pkg/mod
key: gomod-${{ hashFiles('**/go.sum') }}

- name: Test
run: go test -v ./...

lint:
runs-on: ubuntu-latest

timeout-minutes: 10

steps:
- name: Checkout repository
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
with:
fetch-depth: 2

- name: Run golangci-lint
uses: golangci/golangci-lint-action@5c56cd6c9dc07901af25baab6f2b0d9f3b7c3018 # renovate: tag=v2.5.2
with:
# renovate: datasource=go depName=github.com/golangci/golangci-lint
version: v1.44.0

codeql-analyze:
runs-on: ubuntu-latest
permissions:
security-events: write

timeout-minutes: 10

steps:
- name: Checkout repository
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
with:
fetch-depth: 2

- name: Initialize CodeQL
uses: github/codeql-action/init@8b37404d562d866ad6a65d0ecb4fa5131e047ca4 # renovate: tag=v1.0.30
with:
languages: go

- name: Autobuild
uses: github/codeql-action/autobuild@8b37404d562d866ad6a65d0ecb4fa5131e047ca4 # renovate: tag=v1.0.30

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@8b37404d562d866ad6a65d0ecb4fa5131e047ca4 # renovate: tag=v1.0.30

build:
runs-on: ubuntu-latest

timeout-minutes: 10

steps:
# full checkout for semantic-release
- name: Checkout repository
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
with:
fetch-depth: 2

- name: Set up Go
uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # renovate: tag=v2.1.5
with:
# renovate: datasource=golang-version depName=golang
go-version: 1.17.6

- name: Set up Go mod cache
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # renovate: tag=v2.1.7
with:
path: ~/go/pkg/mod
key: gomod-${{ hashFiles('**/go.sum') }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # renovate: tag=v1.6.0

- name: Build binaries
uses: goreleaser/goreleaser-action@79d4afbba1b4eff8b9a98e3d2e58c4dbaf094e2b # renovate: tag=v2.8.1
with:
# renovate: datasource=go depName=github/goreleaser/goreleaser
version: v1.4.1
args: build --rm-dist --single-target --snapshot

- name: Build container images
uses: docker/build-push-action@7f9d37fa544684fb73bfe4835ed7214c255ce02b # renovate: tag=v2.9.0
with:
# Use Path context, so dist directory is available
context: .
tags: ${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max

semantic-release:
needs: [codeql-analyze, build, lint, test]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
packages: write
pull-requests: write

timeout-minutes: 10

steps:
# full checkout for semantic-release
- name: Checkout repository
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # renovate: tag=v2.4.0
with:
fetch-depth: 0
# Use Deploy key with write access to push changelog to main branch (protected branch)
ssh-key: ${{ secrets.SEMANTIC_RELEASE_SSH_KEY }}

- name: Set up Go
uses: actions/setup-go@424fc82d43fa5a37540bae62709ddcc23d9520d4 # renovate: tag=v2.1.5
with:
# renovate: datasource=golang-version depName=golang
go-version: 1.17.6

- name: Set up Go mod cache
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # renovate: tag=v2.1.7
with:
path: ~/go/pkg/mod
key: gomod-${{ hashFiles('**/go.sum') }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # renovate: tag=v1.6.0

- name: Login to GitHub Container Registry
uses: docker/login-action@42d299face0c5c43a0487c477f595ac9cf22f1a7 # renovate: tag=v1.12.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Semantic Release
uses: cycjimmy/semantic-release-action@5982a02995853159735cb838992248c4f0f16166 # renovate: tag=v2.7.0
id: semantic-release
with:
# renovate: datasource=npm depName=semantic-release
semantic_version: 19.0.2
extra_plugins: |
conventional-changelog-conventionalcommits@4.6.3
@semantic-release/changelog@6.0.0
@semantic-release/git@10.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# We rebuild from the release commit, so goreleaser has the correct Git metadata from the Git tag
- name: Build and release binaries
if: ${{ steps.semantic-release.outputs.new_release_published == 'true' }}
uses: goreleaser/goreleaser-action@79d4afbba1b4eff8b9a98e3d2e58c4dbaf094e2b # renovate: tag=v2.8.1
with:
# renovate: datasource=go depName=github/goreleaser/goreleaser
version: v1.4.1
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push container images
if: ${{ steps.semantic-release.outputs.new_release_published == 'true' }}
uses: docker/build-push-action@7f9d37fa544684fb73bfe4835ed7214c255ce02b # renovate: tag=v2.9.0
with:
# Use Path context, so dist directory is available
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x
push: true
tags: |
${{ env.IMAGE_NAME }}:v${{ steps.semantic-release.outputs.new_release_version }}
${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
37 changes: 37 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
run:
timeout: 2m
linters:
enable-all: true
disable:
# Deprectated
- golint
- maligned
- scopelint
- interfacer
# Inappropriate
- exhaustivestruct
- funlen
- gochecknoglobals
- gochecknoinits
- lll
- paralleltest
- varnamelen
- wsl
linters-settings:
cyclop:
max-complexity: 15
errcheck:
exclude-functions:
# Happens on exit via defer
- (*go.uber.org/zap.Logger).Sync
gofumpt:
extra-rules: true
goimports:
local-prefixes: github.com/maxbrunet/bitbucket-semantic-pull-requests
issues:
include:
# Disable excluding of issues about comments from revive.
- EXC0012
- EXC0013
- EXC0014
- EXC0015
23 changes: 23 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
builds:
- main: ./cmd/bitbucket-semantic-pull-requests
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- '386'
- amd64
- arm
- arm64
- ppc64le
- s390x
goarm:
- '7'
archives:
- name_template: '{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{
.Arm }}{{ end }}{{ if .Mips }}-{{ .Mips }}{{ end }}'
format: binary
checksum:
name_template: '{{ .ProjectName }}-checksums.txt'
52 changes: 52 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
analyzeCommits:
releaseRules:
- type: build
release: patch
branches:
- main
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- - "@semantic-release/github"
- labels: false
releasedLabels: false
- - "@semantic-release/changelog"
- changelogFile: CHANGELOG.md
changelogTitle: |-
# Changelog
All notable changes to this project will be documented in this file.
- - "@semantic-release/git"
- assets:
- CHANGELOG.md
message: |-
chore(release): v${nextRelease.version} [skip ci]
${nextRelease.notes}
preset: conventionalcommits
presetConfig:
types:
- type: feat
section: Features
- type: feature
section: Features
- type: fix
section: Bug Fixes
- type: perf
section: Performance Improvements
- type: revert
section: Reverts
- type: docs
section: Documentation
- type: style
section: Styles
- type: chore
section: Miscellaneous Chores
- type: refactor
section: Code Refactoring
- type: test
section: Tests
- type: build
section: Build System
- type: ci
section: Continuous Integration
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM --platform="${BUILDPLATFORM}" docker.io/library/busybox:1.35.0@sha256:e222aa8dfec831b6b89db0062fee021a5f0e6c0564bb80ca052bf039b4d010e9 AS picker

ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT

COPY dist /dist

RUN mkdir /pick && \
if [ "${TARGETARCH}" == 'arm' ]; then \
cp "/dist/bitbucket-semantic-pull-requests_${TARGETOS}_${TARGETARCH}_${TARGETVARIANT##v}/bitbucket-semantic-pull-requests" /pick; \
else \
cp "/dist/bitbucket-semantic-pull-requests_${TARGETOS}_${TARGETARCH}/bitbucket-semantic-pull-requests" /pick; \
fi

FROM gcr.io/distroless/static:nonroot@sha256:80c956fb0836a17a565c43a4026c9c80b2013c83bea09f74fa4da195a59b7a99

LABEL \
org.opencontainers.image.source="https://github.com/maxbrunet/bitbucket-semantic-pull-requests" \
org.opencontainers.image.url="https://github.com/maxbrunet/bitbucket-semantic-pull-requests" \
org.opencontainers.image.licenses="Apache-2.0"

WORKDIR /app

COPY --from=picker /pick/bitbucket-semantic-pull-requests /app

ENTRYPOINT ["/app/bitbucket-semantic-pull-requests"]
Loading

0 comments on commit 1d40148

Please sign in to comment.