2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-12-04 14:02:23 +00:00

chore: enable go, shell, yaml formatters and bazel run //:format (#917)

This commit is contained in:
Greg Magolan 2024-08-20 14:56:40 -04:00 committed by GitHub
parent cccf5ac1b8
commit 11aacaf5df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 36 additions and 56 deletions

View file

@ -1,4 +1,3 @@
---
queue: bazel-lib-default queue: bazel-lib-default
workspaces: workspaces:
.: .:

View file

@ -32,7 +32,6 @@
# `aspect-workflows-` and job names prefixed with `aw-`. Conflicting workflow or # `aspect-workflows-` and job names prefixed with `aw-`. Conflicting workflow or
# job names will result in a bad configuration merge. # job names will result in a bad configuration merge.
version: 2.1 version: 2.1
jobs: jobs:
user-job: user-job:
docker: docker:
@ -40,7 +39,6 @@ jobs:
steps: steps:
- checkout - checkout
- run: echo "Example user CircleCI job that is not generated by Aspect Workflows." - run: echo "Example user CircleCI job that is not generated by Aspect Workflows."
workflows: workflows:
user-workflow: user-workflow:
jobs: jobs:

View file

@ -1,5 +1,4 @@
name: CI name: CI
# Controls when the action will run. # Controls when the action will run.
on: on:
# Triggers the workflow on push or pull request events but only for the main branch # Triggers the workflow on push or pull request events but only for the main branch
@ -7,16 +6,13 @@ on:
branches: [main, 1.x] branches: [main, 1.x]
pull_request: pull_request:
branches: [main, 1.x] branches: [main, 1.x]
# Allows you to run this workflow manually from the Actions tab # Allows you to run this workflow manually from the Actions tab
workflow_dispatch: workflow_dispatch:
concurrency: concurrency:
# Cancel previous actions from the same PR or branch except 'main' branch. # Cancel previous actions from the same PR or branch except 'main' branch.
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info. # See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info.
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}} group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}}
cancel-in-progress: ${{ github.ref_name != 'main' }} cancel-in-progress: ${{ github.ref_name != 'main' }}
jobs: jobs:
# Prepares dynamic test matrix values # Prepares dynamic test matrix values
matrix-prep: matrix-prep:
@ -66,7 +62,6 @@ jobs:
bazel-version: ${{ steps.bazel-version.outputs.res }} bazel-version: ${{ steps.bazel-version.outputs.res }}
config: ${{ steps.config.outputs.res }} config: ${{ steps.config.outputs.res }}
os: ${{ steps.os.outputs.res }} os: ${{ steps.os.outputs.res }}
test: test:
runs-on: ${{ matrix.os }}-latest runs-on: ${{ matrix.os }}-latest
needs: needs:
@ -120,10 +115,8 @@ jobs:
os: macos os: macos
- folder: . - folder: .
os: windows os: windows
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Mount bazel caches - name: Mount bazel caches
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
@ -132,7 +125,6 @@ jobs:
~/.cache/bazel-repository-cache ~/.cache/bazel-repository-cache
key: bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-${{ hashFiles('.bazelrc', '.bazelversion', '.bazeliskrc', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel') }} key: bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-${{ hashFiles('.bazelrc', '.bazelversion', '.bazeliskrc', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel') }}
restore-keys: bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}- restore-keys: bazel-cache-${{ matrix.bazel-version.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-
- name: Configure Bazel version - name: Configure Bazel version
working-directory: ${{ matrix.folder }} working-directory: ${{ matrix.folder }}
shell: bash shell: bash
@ -146,7 +138,6 @@ jobs:
# root .bazelrc brings these in with try-imports. In this CI workflows, we explicitly # root .bazelrc brings these in with try-imports. In this CI workflows, we explicitly
# bring in the version specific bazelrc file with --bazelrc when we invoke bazel. # bring in the version specific bazelrc file with --bazelrc when we invoke bazel.
rm ${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/local/*.bazelrc rm ${GITHUB_WORKSPACE//\\/\/}/.aspect/bazelrc/local/*.bazelrc
- name: Write rbe credentials - name: Write rbe credentials
if: ${{ matrix.config == 'rbe' }} if: ${{ matrix.config == 'rbe' }}
working-directory: ${{ matrix.folder }} working-directory: ${{ matrix.folder }}
@ -156,14 +147,12 @@ jobs:
echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" > $HOME/.bazelrc echo "build --remote_header=x-buildbuddy-api-key=$BUILDBUDDY_API_KEY" > $HOME/.bazelrc
env: env:
BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }}
# TODO: remove this block once we have Aspect CLI Windows releases # TODO: remove this block once we have Aspect CLI Windows releases
- name: Don't use Aspect CLI on Windows - name: Don't use Aspect CLI on Windows
if: matrix.os == 'windows' if: matrix.os == 'windows'
working-directory: ${{ matrix.folder }} working-directory: ${{ matrix.folder }}
shell: bash shell: bash
run: rm -f .bazeliskrc run: rm -f .bazeliskrc
- name: bazel test //... - name: bazel test //...
working-directory: ${{ matrix.folder }} working-directory: ${{ matrix.folder }}
shell: bash shell: bash
@ -178,13 +167,11 @@ jobs:
--build_tag_filters=-skip-on-bazel${{ matrix.bazel-version.major }} \ --build_tag_filters=-skip-on-bazel${{ matrix.bazel-version.major }} \
--enable_bzlmod=${{ matrix.bzlmod }} \ --enable_bzlmod=${{ matrix.bzlmod }} \
//... //...
- name: Integration tests - name: Integration tests
# Don't run integration tests on Windows since they are bash scripts and Windows runs Powershell # Don't run integration tests on Windows since they are bash scripts and Windows runs Powershell
if: matrix.folder == '.' && matrix.os != 'windows' && matrix.bazel-version.major != '6' if: matrix.folder == '.' && matrix.os != 'windows' && matrix.bazel-version.major != '6'
# Find all shell scripts within e2e, echo the filename, execute, fail on error # Find all shell scripts within e2e, echo the filename, execute, fail on error
run: find e2e/*.sh -maxdepth 1 -type f -exec sh -c 'echo "\n\n------------------------------- $0 -------------------------------" && BZLMOD_FLAG=${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} "$0" || kill $PPID' \{\} \; run: find e2e/*.sh -maxdepth 1 -type f -exec sh -c 'echo "\n\n------------------------------- $0 -------------------------------" && BZLMOD_FLAG=${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} "$0" || kill $PPID' \{\} \;
- name: Verify bcr patches - name: Verify bcr patches
if: matrix.folder == '.' && matrix.bzlmod == '1' && matrix.os == 'ubuntu' && matrix.bazel-version.major != '6' if: matrix.folder == '.' && matrix.bzlmod == '1' && matrix.os == 'ubuntu' && matrix.bazel-version.major != '6'
run: patch --dry-run -p1 < .bcr/patches/*.patch run: patch --dry-run -p1 < .bcr/patches/*.patch

View file

@ -1,15 +1,12 @@
name: Verify PR title/description name: Verify PR title/description
on: on:
pull_request_target: pull_request_target:
types: types:
- opened - opened
- edited - edited
- synchronize - synchronize
permissions: permissions:
pull-requests: read pull-requests: read
jobs: jobs:
check: check:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View file

@ -2,12 +2,10 @@
# You should use an annotated tag, like `git tag -a v1.2.3` # You should use an annotated tag, like `git tag -a v1.2.3`
# and put the release notes into the commit message for the tag. # and put the release notes into the commit message for the tag.
name: Release name: Release
on: on:
push: push:
tags: tags:
- "v*.*.*" - "v*.*.*"
jobs: jobs:
build: build:
# Go cross-compilation works from linux -> any platform # Go cross-compilation works from linux -> any platform
@ -28,7 +26,6 @@ jobs:
name: artifacts name: artifacts
path: artifacts/ path: artifacts/
retention-days: 1 retention-days: 1
release: release:
needs: build needs: build
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -37,10 +34,8 @@ jobs:
# Fetch the built artifacts from build jobs above and extract into # Fetch the built artifacts from build jobs above and extract into
# ${GITHUB_WORKSPACE}/artifacts/* # ${GITHUB_WORKSPACE}/artifacts/*
- uses: actions/download-artifact@v4 - uses: actions/download-artifact@v4
- name: Prepare workspace snippet - name: Prepare workspace snippet
run: .github/workflows/release_prep.sh > release_notes.txt run: .github/workflows/release_prep.sh > release_notes.txt
- uses: softprops/action-gh-release@v2 - uses: softprops/action-gh-release@v2
with: with:
# Use GH feature to populate the changelog automatically # Use GH feature to populate the changelog automatically

View file

@ -5,7 +5,6 @@
# Commitizen runs in commit-msg stage # Commitizen runs in commit-msg stage
# but we don't want to run the other hooks on commit messages # but we don't want to run the other hooks on commit messages
default_stages: [commit] default_stages: [commit]
repos: repos:
# Check formatting and lint for starlark code # Check formatting and lint for starlark code
- repo: https://github.com/keith/pre-commit-buildifier - repo: https://github.com/keith/pre-commit-buildifier

View file

@ -5,4 +5,3 @@ bats_load_library "bats-assert"
run echo 'have' run echo 'have'
assert_output 'have' assert_output 'have'
} }

View file

@ -5,4 +5,3 @@ bats_load_library 'bats-custom'
@test 'env' { @test 'env' {
run custom_test_fn run custom_test_fn
} }

View file

@ -5,4 +5,3 @@ bats_load_library 'bats-assert'
run echo 'have' run echo 'have'
assert_output 'have' assert_output 'have'
} }

View file

@ -5,4 +5,3 @@ bats_load_library 'bats-assert'
run echo $USE_BAZEL_VERSION run echo $USE_BAZEL_VERSION
assert_output 'latest' assert_output 'latest'
} }

View file

@ -7,4 +7,3 @@ bats_load_library 'bats-file'
assert_output 'lib/tests/bats/data.bin' assert_output 'lib/tests/bats/data.bin'
assert_file_exists 'lib/tests/bats/data.bin' assert_file_exists 'lib/tests/bats/data.bin'
} }

View file

@ -3,8 +3,9 @@
package common package common
import ( import (
"golang.org/x/sys/unix"
"os" "os"
"golang.org/x/sys/unix"
) )
// https://keith.github.io/xcode-man-pages/clonefile.2.html // https://keith.github.io/xcode-man-pages/clonefile.2.html

View file

@ -13,10 +13,12 @@ import (
type pathSet map[string]bool type pathSet map[string]bool
var srcPaths = pathSet{} var (
var hardlink = false srcPaths = pathSet{}
var verbose = false hardlink = false
var preserveMTime = false verbose = false
preserveMTime = false
)
type walker struct { type walker struct {
queue chan<- common.CopyOpts queue chan<- common.CopyOpts

View file

@ -47,11 +47,15 @@ type config struct {
TargetWorkspace *string TargetWorkspace *string
} }
type copyMap map[string]fileInfo type (
type pathSet map[string]bool copyMap map[string]fileInfo
pathSet map[string]bool
)
var copySet = copyMap{} var (
var mkdirSet = pathSet{} copySet = copyMap{}
mkdirSet = pathSet{}
)
func parseConfig(configPath string, wkspName *string) (*config, error) { func parseConfig(configPath string, wkspName *string) (*config, error) {
f, err := os.Open(configPath) f, err := os.Open(configPath)

View file

@ -60,9 +60,9 @@ func main() {
content = strings.ReplaceAll(content, key, value) content = strings.ReplaceAll(content, key, value)
} }
var mode os.FileMode = 0666 var mode os.FileMode = 0o666
if executable { if executable {
mode = 0777 mode = 0o777
} }
err = os.WriteFile(args[1], []byte(content), mode) err = os.WriteFile(args[1], []byte(content), mode)
if err != nil { if err != nil {
@ -89,5 +89,4 @@ func parseStatusFile(statusFilePath string) (map[string]string, error) {
} }
return results, nil return results, nil
} }

View file

@ -2,11 +2,10 @@ load("@aspect_rules_lint//format:defs.bzl", "format_multirun")
format_multirun( format_multirun(
name = "format", name = "format",
# TODO: enable formatters in follow-up PR go = "@aspect_rules_lint//format:gofumpt",
# go = "@aspect_rules_lint//format:gofumpt", shell = "@aspect_rules_lint//format:shfmt",
# shell = "@aspect_rules_lint//format:shfmt",
starlark = "@buildifier_prebuilt//:buildifier", starlark = "@buildifier_prebuilt//:buildifier",
tags = ["manual"], tags = ["manual"],
visibility = ["//:__subpackages__"], visibility = ["//:__subpackages__"],
# yaml = "@aspect_rules_lint//format:yamlfmt", yaml = "@aspect_rules_lint//format:yamlfmt",
) )

5
yamlfmt.yaml Normal file
View file

@ -0,0 +1,5 @@
gitignore_excludes: true
doublestar: true
exclude:
- .circleci/config.yml
- lib/tests/yq/empty.yaml