Skip to content

Commit

Permalink
Merge branch 'main' of github.com:/viamrobotics/rplidar into v0.1.16-…
Browse files Browse the repository at this point in the history
…release
  • Loading branch information
jeremyrhyde committed Dec 5, 2023
2 parents aea7741 + 80ad600 commit 1a698aa
Show file tree
Hide file tree
Showing 14 changed files with 1,039 additions and 143 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/appimage-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Comment on PR'

on:
workflow_run:
workflows: ["Pull Request Update"]
types:
- completed

jobs:
comment:
name: 'Post Comment on PR'
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request_target' && github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download PR Variables
uses: dawidd6/action-download-artifact@v2
with:
run_id: ${{ github.event.workflow_run.id }}
name: pr-variables

- name: Restore Environment
run: cat pr.env >> "${GITHUB_ENV}"

- name: Add AppImage Links
if: ${{ env.APPIMAGE }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: AppImage
number: ${{ env.PR_NUMBER }}
recreate: true
message: |
AppImages ready!
<https://storage.googleapis.com/packages.viam.com/apps/rplidar/rplidar-module-pr-${{ env.PR_NUMBER }}-aarch64.AppImage>
<https://storage.googleapis.com/packages.viam.com/apps/rplidar/rplidar-module-pr-${{ env.PR_NUMBER }}-x86_64.AppImage>
24 changes: 20 additions & 4 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ jobs:
container:
image: ${{ matrix.image }}
options: --platform ${{ matrix.platform }}
timeout-minutes: 15
timeout-minutes: 30
outputs:
date: ${{ steps.build_date.outputs.date }}

steps:
- name: Check out code
if: inputs.release_type != 'pr'
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Check out PR branch code
if: inputs.release_type == 'pr'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2

- name: Clean and Fix Permissions
run: |
Expand All @@ -51,17 +59,25 @@ jobs:
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'


- name: Make Setup
run: |
chown testbot:testbot -R .
sudo -Hu testbot bash -lc 'make setup'
- name: Build and Package (PR)
if: inputs.release_type == 'pr'
run: |
sudo -u testbot bash -lc 'make BUILD_CHANNEL="pr-${{ github.event.pull_request.number }}" appimage'
- name: Build and Package (Latest)
if: inputs.release_type == 'latest'
run: |
apt-get -y install swig
sudo -Hu testbot bash -lc 'make BUILD_CHANNEL="latest" appimage'
- name: Build and Package (Tagged)
if: inputs.release_type == 'stable' || inputs.release_type == 'rc'
run: |
apt-get -y install swig
sudo -Hu testbot bash -lc 'make RELEASE_TYPE="${{ inputs.release_type }}" BUILD_CHANNEL="${{ github.ref_name }}" appimage'
- name: Deploy Files
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy_module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
container:
image: ${{ matrix.image }}
options: --platform linux/${{ matrix.platform }}
timeout-minutes: 15
timeout-minutes: 30
outputs:
date: ${{ steps.build_date.outputs.date }}

Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
- id: stripped-version
run: echo version=${VERSION#v} >> $GITHUB_OUTPUT
- uses: viamrobotics/upload-module@main
if: github.event_name == 'release'
if: github.event_name == 'release' && !contains(github.ref_name, 'rc')
with:
platform: linux/${{ matrix.platform }}
version: ${{ steps.stripped-version.outputs.version }}
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PR Test Label Manager

on:
pull_request_target:
branches: [ 'main' ]
types: [ opened, synchronize, reopened ]

jobs:
pr_test_label_manager:
name: PR Test Label Manager
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request_target' &&
contains(fromJson('["opened", "synchronize", "reopened"]'), github.event.action)
steps:
- name: "Check Membership and Label PR"
uses: actions/github-script@v6
id: check-membership
with:
github-token: ${{ secrets.PR_TOKEN }}
script: |
let prNumber = context.payload.pull_request && context.payload.pull_request.number;
try {
await github.rest.issues.removeLabel({owner: "viamrobotics", repo: "rplidar", issue_number: prNumber, name: "safe to test"});
} catch (err) {
core.info(`Non-fatal error ${err}, while trying to remove 'safe to test' label.`);
}
let orgResp = await github.rest.orgs.checkMembershipForUser({org: "viamrobotics", username: context.payload.sender.login});
if (orgResp.status === 204) {
// order of labeling events must be preserved, so two seperate calls
await github.rest.issues.addLabels({owner: "viamrobotics", repo: "rplidar", issue_number: prNumber, labels: ["safe to test"]});
return true;
}
return false;
- name: Add Unsafe PR Comment
if: steps.check-membership.outputs.result != 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
message: For security reasons, this PR must be labeled with `safe to test` in order for tests to run.
45 changes: 45 additions & 0 deletions .github/workflows/pullrequest-trusted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

name: Pull Request Update

concurrency:
group: pullrequest-${{ github.head_ref }}
cancel-in-progress: true

on:
pull_request_target:
branches: [ 'main' ]
types: [ 'labeled' ]

# To test workflow updates you need to work in a branch directly on viamrobotics/rplidar
# and tag your working branch instead of @main in any viamrobotics/rplidar "uses" below.
# Don't forget to tag back to @main before merge.

jobs:
test:
if: github.event.label.name == 'safe to test' ||
contains(github.event.pull_request.labels.*.name, 'appimage') ||
contains(github.event.pull_request.labels.*.name, 'appimage-ignore-tests')
uses: viamrobotics/rplidar/.github/workflows/test.yml@main

# This lets people add an "appimage" tag to have appimages built for the PR
appimage:
needs: [test]
if: |
always() && !cancelled() && contains(github.event.pull_request.labels.*.name, 'safe to test') &&
!contains(github.event.pull_request.labels.*.name, 'appimage-ignore-tests') &&
contains(github.event.pull_request.labels.*.name, 'appimage') && needs.test.result == 'success'
uses: viamrobotics/rplidar/.github/workflows/appimage.yml@main
with:
release_type: 'pr'
secrets:
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}

appimage-ignore-tests:
if: |
always() && !cancelled() && contains(github.event.pull_request.labels.*.name, 'safe to test') &&
contains(github.event.pull_request.labels.*.name, 'appimage-ignore-tests')
uses: viamrobotics/rplidar/.github/workflows/appimage.yml@main
with:
release_type: 'pr'
secrets:
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
28 changes: 28 additions & 0 deletions .github/workflows/pullrequestclose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Pull Request Close

concurrency:
group: pullrequest-${{ github.head_ref }}
cancel-in-progress: true

on:
pull_request_target:
branches: [ 'main' ]
types: [ 'closed' ]

jobs:
appimage_clean:
name: Remove PR AppImages
runs-on: ubuntu-latest

steps:
- name: Authorize GCP
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: Delete Files
run: |
gsutil rm "gs://packages.viam.com/apps/rplidar-module/rplidar-module-pr-${{ github.event.pull_request.number }}-*" || true
83 changes: 83 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Test

on:
workflow_dispatch:
workflow_call:

jobs:
build_and_test:
name: Build and Test RPLiDAR
strategy:
matrix:
include:
- arch: buildjet-8vcpu-ubuntu-2204
image: ghcr.io/viamrobotics/canon:amd64-cache
platform: linux/amd64
- arch: buildjet-8vcpu-ubuntu-2204-arm
image: ghcr.io/viamrobotics/canon:arm64-cache
platform: linux/arm64
runs-on: ${{ matrix.arch }}
container:
image: ${{ matrix.image }}
options: --platform ${{ matrix.platform }}
timeout-minutes: 45
steps:
# Can't directly comment without token having full read/write access
# appimage-comment.yml will trigger separately and post the actual comments

- name: Set PR Number variable
run: |
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> pr.env
- name: Set appimage variable
if: contains(github.event.pull_request.labels.*.name, 'appimage') || contains(github.event.pull_request.labels.*.name, 'appimage-ignore-tests')
run: |
echo "APPIMAGE=true" >> pr.env
- name: Upload PR variables
uses: actions/upload-artifact@v3
with:
name: pr-variables
path: |
pr.env
retention-days: 1

- name: Check out main branch code
if: github.event_name != 'pull_request_target'
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Check out PR branch code
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2

- name: Clean and Fix Permissions
run: |
chown testbot:testbot -R .
sudo -Hu testbot bash -lc 'make clean'
- name: make setup
run: |
sudo -u testbot bash -lc 'make setup'
- name: make test
run: |
sudo -u testbot bash -lc 'make test'
- name: Verify no uncommitted changes from make lint
run: |
git init
git add .
chown -R testbot:testbot .
sudo -u testbot bash -lc 'sudo apt-get install -y clang-format && make lint'
GEN_DIFF=$(git status -s --ignore-submodules)
if [ -n "$GEN_DIFF" ]; then
echo '"make lint" resulted in changes not in git' 1>&2
git status
exit 1
fi
39 changes: 25 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,31 @@ GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n')
TAG_VERSION?=$(shell git tag --points-at | sort -Vr | head -n1)
CGO_LDFLAGS="-L 'gen/third_party/rplidar_sdk-release-${VERSION}/sdk/output/${OS}/Release/'"
GO_BUILD_LDFLAGS = -ldflags "-X 'main.Version=${TAG_VERSION}' -X 'main.GitRevision=${GIT_REVISION}'"
GOPATH = $(HOME)/go/bin
export PATH := ${GOPATH}:$(PATH)
SHELL := /usr/bin/env bash

default: setup build-module

setup: install-dependencies

install-dependencies:
ifneq (, $(shell which brew))
brew update
brew install make swig pkg-config jpeg
else ifneq (, $(shell which apt-get))
$(warning "Installing rplidar external dependencies via APT.")
sudo apt-get update
sudo apt install -y make swig libjpeg-dev pkg-config
else
$(error "Unsupported system. Only apt and brew currently supported.")
endif

.PHONY: default
default: build-module

.PHONY: goformat
goformat:
go install golang.org/x/tools/cmd/goimports
gofmt -s -w .
goimports -w -local=go.viam.com/utils `go list -f '{{.Dir}}' ./... | grep -Ev "proto"`

.PHONY: lint
lint: goformat
go install github.com/edaniels/golinters/cmd/combined
go install github.com/golangci/golangci-lint/cmd/golangci-lint
Expand All @@ -24,27 +38,24 @@ lint: goformat
go list -f '{{.Dir}}' ./... | grep -v gen | xargs `go env GOPATH`/bin/go-errorlint -errorf
go list -f '{{.Dir}}' ./... | grep -v gen | xargs go run github.com/golangci/golangci-lint/cmd/golangci-lint run -v --config=./etc/.golangci.yaml

.PHONY: test
test:
go test -v -coverprofile=coverage.txt -covermode=atomic ./...

.PHONY: sdk
sdk:
cd gen/third_party/rplidar_sdk-release-${VERSION}/sdk && $(MAKE)

.PHONY: clean-sdk
clean-sdk:
cd gen/third_party/rplidar_sdk-release-${VERSION}/sdk && $(MAKE) clean_sdk

.PHONY: swig
swig: sdk
cd gen && swig -v -go -cgo -c++ -intgosize 64 gen.i

.PHONY: build-module
build-module: swig
mkdir -p bin && CGO_LDFLAGS=${CGO_LDFLAGS} go build $(GO_BUILD_LDFLAGS) -o bin/rplidar-module module/main.go

.PHONY: clean
install:
sudo cp bin/rplidar-module /usr/local/bin/rplidar-module

test: swig
CGO_LDFLAGS=${CGO_LDFLAGS} go test -v -coverprofile=coverage.txt -covermode=atomic ./... -race

clean: clean-sdk
rm -rf bin gen/gen_wrap.cxx gen/gen.go

Expand Down
Loading

0 comments on commit 1a698aa

Please sign in to comment.