Skip to content

Commit

Permalink
Add pre commit (#380)
Browse files Browse the repository at this point in the history
* Add .pre-commit-config.yaml and .yamllint
* 'pre-commit run --all-files'. Manually fix some yaml complaints.
* Exclude some files from whitespace changes.
* Switch out docker image to quay (astronomer/issues#1355)
* Be specific about regex types
* Require at least one digit in each section
  • Loading branch information
danielhoherd authored Nov 5, 2020
1 parent b28c6a4 commit 802e1a9
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: 2.1
jobs:
test:
Expand All @@ -9,7 +10,7 @@ jobs:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
- image: astronomerinc/ap-houston-api:latest
- image: quay.io/astronomer/ap-houston-api:latest
name: houston
entrypoint: "yarn start"
environment:
Expand Down
42 changes: 29 additions & 13 deletions .circleci/next_version.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
import os
import re
import sys

from github import Github
from packaging.version import parse as semver

branch = os.environ['CIRCLE_BRANCH']
org = os.environ['GIT_ORG']
repository = os.environ['CIRCLE_PROJECT_REPONAME']
branch = os.environ["CIRCLE_BRANCH"]
org = os.environ["GIT_ORG"]
repository = os.environ["CIRCLE_PROJECT_REPONAME"]
github = Github()
repo = github.get_repo(f'{ org }/{ repository }')
repo = github.get_repo(f"{org}/{repository}")

release_regex = re.compile("release-(\d*\.\d*)")
release_regex = re.compile(r"release-(\d+\.\d+)")
major_minor_version = release_regex.findall(branch)
most_recent_tag = None

if not len(major_minor_version):
raise Exception("ERROR: we are not on a release branch. Branch should be named release-X.Y where X and Y are positive integers")
raise Exception(
"ERROR: we are not on a release branch. Branch should be named release-X.Y where X and Y are positive integers"
)
major_minor_version = major_minor_version[0]
print(f"We are on a release branch: {branch}, detected major.minor version {major_minor_version}", file=sys.stderr)
print(f"We will find the most recent patch version of {major_minor_version} and return it incremented by one", file=sys.stderr)
print(
f"We are on a release branch: {branch}, detected major.minor version {major_minor_version}",
file=sys.stderr,
)
print(
f"We will find the most recent patch version of {major_minor_version} and return it incremented by one",
file=sys.stderr,
)
for release in repo.get_releases():
version = semver(release.tag_name).release
if not version:
continue
this_major_minor = f"{version[0]}.{version[1]}"
if this_major_minor == major_minor_version:
most_recent_tag = release.tag_name
print(f"The most recent tag matching this release is {most_recent_tag}", file=sys.stderr)
print(
f"The most recent tag matching this release is {most_recent_tag}",
file=sys.stderr,
)
break

if most_recent_tag:
Expand All @@ -37,11 +49,15 @@
patch += 1
new_version = ".".join(str(i) for i in [major, minor, patch])
else:
print("Did not detect a most recent version. Setting patch number to zero.", file=sys.stderr)
print(
"Did not detect a most recent version. Setting patch number to zero.",
file=sys.stderr,
)
new_version = major_minor_version + ".0"

new_tag_regex = re.compile('\d*\.\d*\.\d*')
assert len(new_tag_regex.findall(new_version)), \
f"Error, did not produce a new tag in the form {new_tag_regex.pattern}"
new_tag_regex = re.compile(r"\d+\.\d+\.\d+")
assert len(
new_tag_regex.findall(new_version)
), f"Error, did not produce a new tag in the form {new_tag_regex.pattern}"
print(f"Calculated new version as {new_version}", file=sys.stderr)
sys.stdout.write(new_version)
18 changes: 8 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
.astro/
.DS_Store
.idea/
.vscode/
astro
meta/
astro-cli
cover.out
coverage.txt
dist/
meta/
packages.txt
requirements.txt

# IDEs
.idea/
.vscode/
.DS_Store
coverage.txt
cover.out
astro-cli
vendor/github.com/theupdateframework/notary/Dockerfile
vendor/github.com/theupdateframework/notary/Dockerfile
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
project_name: astro
release:
github:
Expand Down Expand Up @@ -26,7 +27,7 @@ brews:
owner: astronomer
name: homebrew-tap
folder: Formula
homepage: https://astronomer.io
homepage: https://astronomer.io
description: To build and run Airflow DAGs locally via docker-compose and deploy DAGs to Astronomer-managed Airflow clusters and interact with the Astronomer API.
test: |
system "#{bin}/astro version"
Expand Down
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
exclude: '(vendor|.vscode)' # regex
repos:
- repo: local
hooks:
- id: go-fmt
name: go fmt
types: [go]
language: system
entry: 'gofmt -w -s'
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-toml
- id: check-xml
- id: check-yaml
args: ['--allow-multiple-documents']
- id: detect-private-key
- id: end-of-file-fixer
- id: file-contents-sorter
args: ['--ignore-case']
files: '^\.gitignore$' # regex
- id: mixed-line-ending
args: ['--fix=lf']
- id: no-commit-to-branch
args: ['-b', 'main']
- id: pretty-format-json
args: ['--autofix', '--no-ensure-ascii']
- id: sort-simple-yaml
- id: trailing-whitespace
exclude: '.*_test.go$' # regex
- repo: https://github.com/detailyang/pre-commit-shell
rev: 1.0.5
hooks:
- id: shell-lint
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.25.0
hooks:
- id: yamllint
- repo: https://github.com/astronomer/pre-commit-hooks
rev: fdcede7a5c8ea762c903f242279112161cf35d9f
hooks:
- id: CVE-2017-18342
- id: remove-en-dashes
- id: remove-unicode-non-breaking-spaces
- id: remove-unicode-zero-width-non-breaking-spaces
- id: remove-unicode-zero-width-space
17 changes: 17 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# https://yamllint.readthedocs.io/en/stable/configuration.html#default-configuration
extends: default

ignore: |
vendor

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
line-length: disable
truthy: disable
comments-indentation: disable
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ENV PATH /go/bin:$PATH

RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin

WORKDIR $GOPATH
WORKDIR $GOPATH
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_COMMIT_SHORT=$(shell git rev-parse --short HEAD)
VERSION ?= SNAPSHOT-${GIT_COMMIT_SHORT}

LDFLAGS_VERSION=-X github.com/astronomer/astro-cli/version.CurrVersion=${VERSION}
LDFLAGS_VERSION=-X github.com/astronomer/astro-cli/version.CurrVersion=${VERSION}
LDFLAGS_GIT_COMMIT=-X github.com/astronomer/astro-cli/version.CurrCommit=${GIT_COMMIT}

.DEFAULT_GOAL := build
Expand Down
38 changes: 19 additions & 19 deletions cmd/airflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func newAirflowDeployCmd(client *houston.Client, out io.Writer) *cobra.Command {

func newAirflowStartCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Start a development airflow cluster",
Long: "Start a development airflow cluster",
Args: cobra.MaximumNArgs(1),
Use: "start",
Short: "Start a development airflow cluster",
Long: "Start a development airflow cluster",
Args: cobra.MaximumNArgs(1),
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
Expand All @@ -138,9 +138,9 @@ func newAirflowStartCmd(client *houston.Client, out io.Writer) *cobra.Command {

func newAirflowKillCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "kill",
Short: "Kill a development airflow cluster",
Long: "Kill a development airflow cluster",
Use: "kill",
Short: "Kill a development airflow cluster",
Long: "Kill a development airflow cluster",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
Expand All @@ -153,9 +153,9 @@ func newAirflowKillCmd(client *houston.Client, out io.Writer) *cobra.Command {

func newAirflowLogsCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "logs",
Short: "Output logs for a development airflow cluster",
Long: "Output logs for a development airflow cluster",
Use: "logs",
Short: "Output logs for a development airflow cluster",
Long: "Output logs for a development airflow cluster",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
Expand All @@ -171,9 +171,9 @@ func newAirflowLogsCmd(client *houston.Client, out io.Writer) *cobra.Command {

func newAirflowStopCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "stop",
Short: "Stop a development airflow cluster",
Long: "Stop a development airflow cluster",
Use: "stop",
Short: "Stop a development airflow cluster",
Long: "Stop a development airflow cluster",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
Expand All @@ -186,9 +186,9 @@ func newAirflowStopCmd(client *houston.Client, out io.Writer) *cobra.Command {

func newAirflowPSCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "ps",
Short: "List airflow containers",
Long: "List airflow containers",
Use: "ps",
Short: "List airflow containers",
Long: "List airflow containers",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
Expand All @@ -201,9 +201,9 @@ func newAirflowPSCmd(client *houston.Client, out io.Writer) *cobra.Command {

func newAirflowRunCmd(client *houston.Client, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "Run any command inside airflow webserver",
Long: "Run any command inside airflow webserver",
Use: "run",
Short: "Run any command inside airflow webserver",
Long: "Run any command inside airflow webserver",
// ignore PersistentPreRunE of root command
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Correct arguments for SHELL are: "bash" and "zsh".
Notes:
1) zsh completions requires zsh 5.2 or newer.
2) macOS users have to install bash-completion framework to utilize
completion features. This can be done using homebrew:
brew install bash-completion
Expand Down
4 changes: 2 additions & 2 deletions cmd/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ var (
`
deploymentAirflowUpgradeExample = `
$ astro deployment airflow upgrade --deployment-id=<deployment-id> --desired-airflow-version=<desired-airflow-version>
# Abort the initial airflow upgrade step:
# Abort the initial airflow upgrade step:
$ astro deployment airflow upgrade --cancel --deployment-id=<deployment-id>
`

Expand Down
1 change: 0 additions & 1 deletion cmd/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func TestDeploymentAirflowUpgradeCommand(t *testing.T) {
assert.Contains(t, output, expectedOut)
}


func TestDeploymentAirflowUpgradeCancelCommand(t *testing.T) {
testUtil.InitTestConfig()
expectedOut := `Airflow upgrade process has been successfully canceled. Your Deployment was not interrupted and you are still running Airflow 1.10.5.`
Expand Down
2 changes: 1 addition & 1 deletion cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
# Subscribe logs from airflow workers for last 5 min and specify search term, and subscribe to more.
astro deployment logs workers example-deployment-uuid --follow --search "some search terms"
# Return logs from airflow webserver for last 25 min.
astro deployment logs webserver example-deployment-uuid --since 25m
Expand Down
6 changes: 3 additions & 3 deletions cmd/serviceaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ func newSaRootCmd(_ *houston.Client, _ io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "service-account",
Aliases: []string{"sa"},
Deprecated: `please use commands instead:
$ astro workspace service-account
or
Deprecated: `please use commands instead:
$ astro workspace service-account
or
$ astro deployment service-account
`,
}
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
coverage:
range: 52..100
round: down
Expand Down
2 changes: 1 addition & 1 deletion docker/testfiles/Dockerfile.ok
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM quay.io/astronomer/ap-airflow:latest-onbuild
FROM quay.io/astronomer/ap-airflow:latest-onbuild

0 comments on commit 802e1a9

Please sign in to comment.