Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vlnevyhosteny authored Jan 2, 2024
0 parents commit 6021bfe
Show file tree
Hide file tree
Showing 22 changed files with 797 additions and 0 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/setup-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Setup repository
on:
push:
paths:
- cookiecutter.json
jobs:
setup:
name: Reinitialize repository
runs-on: ubuntu-latest
env:
REPO_SETUP_TOKEN: ${{ secrets.REPO_SETUP_TOKEN }}
steps:
- name: Do not run scaffolding on template repository
shell: bash
# This workflow runs when the `cookiecutter.json` file is modified.
# This is the trick to re-init a repository, but we don't want to
# run this action if this file is modified in the origin template repository.
#
# Using the GitHub rest API allows us to identify if the current repository
# is a template repository or not.
run: |
curl --silent -X GET \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.baptiste-preview+json" \
https://api.github.com/repos/$GITHUB_REPOSITORY \
| jq --exit-status '.is_template == false';
- id: string
uses: ASzc/change-string-case-action@v2
with:
string: ${{ github.repository }}

- uses: actions/checkout@v4
with:
# Committing workflow files using the regular GITHUB_TOKEN will fail with
# `Git Error: Refusing to allow a GitHub App to create or update workflow without workflows permission`.
# This is by design to prevent third-parties from adding malicious workflow files.
#
# Generate a new personal access token with the workflow `scope` does the trick.
# Checkout my blog post https://stefanbuck.com/blog for alternative options
token: ${{ env.REPO_SETUP_TOKEN || secrets.GITHUB_TOKEN }}

- uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: pip install cookiecutter

- name: Scaffolding repository
# cookiecutter is command-line utility to create projects from templates
# https://github.com/cookiecutter/cookiecutter
#
# --no-input Do not prompt for parameters and only use
# cookiecutter.json file content
#
# --output-dir Where to output the generated project dir into
run: cookiecutter . --no-input --output-dir ./cookiecutter-temp

- name: Prepare root directory
shell: bash
run: |
find ./ -maxdepth 1 \
! -name '.git' \
! -name 'cookiecutter-temp' \
! -name '.' \
! -exec rm -rf {} +
- name: Move files to root
shell: bash
# The cookiecutter-temp/ folder contains a single folder which is the
# generated project by cookiecutter. We want to move all the project
# files into the root directory so we can reinitialize git in the next step
run: |
rsync -r ./cookiecutter-temp/*/ . && \
rm -rf ./cookiecutter-temp/
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'

- name: go mod init
shell: bash
run: |
go mod init "github.com/${{ steps.string.outputs.lowercase }}" && \
go mod tidy && \
go mod vendor
- name: Reinitialize git repository
shell: bash
# Reinitialize git after scaffolding this repository.
# We use `git checkout --orphan` to create a branch in a git init-like state.
# By force pushing this as `main` we end up with a new clean git history.
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com" && \
git config --global user.name "github-actions[bot]" && \
git checkout --orphan temp-branch && \
git add . && \
git commit -m 'Initial commit' && \
git push origin temp-branch:main -f
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
build/
*.c1z

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
dist/
cookiecutter-temp/
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# baton-template
A simple template for quickly building your own Baton connector.

## How to use
1. Click on the "use this template" button, and you'll have a new repository for your connector.
2. Update `cookiecutter.json` with the appropriate configuration
```json
{
"repo_owner": "conductorone",
"repo_name": "baton-example",
"name": "baton-example"
}
```
10. Commit this change, and a Github action will process the update and initialize the repo for you.
5 changes: 5 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"repo_owner": "conductorone",
"repo_name": "baton-example",
"name": "baton-example"
}
34 changes: 34 additions & 0 deletions {{cookiecutter.name}}/.github/workflows/capabilities.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Generate connector capabilities

on:
push:
branches:
- main

jobs:
calculate-capabilities:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ '{{ secrets.RELENG_GITHUB_TOKEN }}' }}

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Build
run: go build -o connector ./cmd/{{ cookiecutter.name }}

- name: Run and save output
run: ./connector capabilities > baton_capabilities.json

- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'Updating baton capabilities.'
add: 'baton_capabilities.json'
38 changes: 38 additions & 0 deletions {{cookiecutter.name}}/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ci
on: pull_request
jobs:
go-lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v3
- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=3m
go-test:
strategy:
matrix:
go-version: [1.20.x]
platform: [ubuntu-latest]
runs-on: ${{ '{{ matrix.platform }}' }}
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v4
with:
go-version: ${{ '{{ matrix.go-version }}' }}
- name: Checkout code
uses: actions/checkout@v3
- name: go tests
run: go test -v -covermode=count -json ./... > test.json
- name: annotate go tests
if: always()
uses: guyarb/[email protected]
with:
test-results: test.json
41 changes: 41 additions & 0 deletions {{cookiecutter.name}}/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: main ci
on:
push:
branches:
- main
jobs:
go-lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v3
- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=3m
go-test:
strategy:
matrix:
go-version: [ 1.20.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ '{{ matrix.platform }}' }}
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v4
with:
go-version: ${{ '{{ matrix.go-version }}' }}
- name: Checkout code
uses: actions/checkout@v3
- name: go tests
run: go test -v -covermode=count -json ./... > test.json
- name: annotate go tests
if: always()
uses: guyarb/[email protected]
with:
test-results: test.json
60 changes: 60 additions & 0 deletions {{cookiecutter.name}}/.github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Release

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Set up Gon
run: brew tap mitchellh/gon && brew install mitchellh/gon/gon
- name: Import Keychain Certs
uses: apple-actions/import-codesign-certs@v1
with:
p12-file-base64: ${{ '{{ secrets.APPLE_SIGNING_KEY_P12 }}' }}
p12-password: ${{ '{{ secrets.APPLE_SIGNING_KEY_P12_PASSWORD }}' }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ '{{ secrets.RELENG_GITHUB_TOKEN }}' }}
AC_PASSWORD: ${{ '{{ secrets.AC_PASSWORD }}' }}
goreleaser-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ '{{ github.repository_owner }}' }}
password: ${{ '{{ secrets.RELENG_GITHUB_TOKEN }}' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean -f .goreleaser.docker.yaml
env:
GITHUB_TOKEN: ${{ '{{ secrets.RELENG_GITHUB_TOKEN }}' }}
17 changes: 17 additions & 0 deletions {{cookiecutter.name}}/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
*.c1z

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
dist/
Loading

0 comments on commit 6021bfe

Please sign in to comment.