From 5fed4e80a7b33a914d32f2a509b869c9de64c599 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 19:22:59 -0400 Subject: [PATCH 1/5] Add a CI job to run clippy for every push. --- .lighthouse/pipeline-clippy.yaml | 172 +++++++++++++++++++++++++++++++ .lighthouse/triggers.yaml | 7 ++ 2 files changed, 179 insertions(+) create mode 100644 .lighthouse/pipeline-clippy.yaml diff --git a/.lighthouse/pipeline-clippy.yaml b/.lighthouse/pipeline-clippy.yaml new file mode 100644 index 00000000..ab29a783 --- /dev/null +++ b/.lighthouse/pipeline-clippy.yaml @@ -0,0 +1,172 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: clippy +spec: + pipelineSpec: + params: + - name: image-name + description: The name for the built image + type: string + - name: path-to-image-context + description: The path to the build context + type: string + - name: path-to-dockerfile + description: The path to the Dockerfile + type: string + - name: GIT_USER_NAME + description: The username for git + type: string + default: "fluxcdbot" + - name: GIT_USER_EMAIL + description: The email for git + type: string + default: "fluxcdbot@users.noreply.github.com" + tasks: + - name: do-stuff + taskSpec: + metadata: {} + stepTemplate: + image: alpine:3.18 + name: "" + resources: + requests: + cpu: 10m + memory: 600Mi + workingDir: /workspace/source + steps: + - image: alpine:3.18 + name: do-stuff-step + script: | + #!/usr/bin/env sh + echo "hello world" + - name: report-pending + taskRef: + name: gitea-set-status + runAfter: + - fetch-repository + params: + - name: CONTEXT + value: "$(params.JOB_NAME)" + - name: REPO_FULL_NAME + value: "$(params.REPO_OWNER)/$(params.REPO_NAME)" + - name: GITEA_HOST_URL + value: code.fizz.buzz + - name: SHA + value: "$(tasks.fetch-repository.results.commit)" + - name: DESCRIPTION + value: "Build $(params.JOB_NAME) has started" + - name: STATE + value: pending + - name: TARGET_URL + value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)" + - name: fetch-repository + taskRef: + name: git-clone + workspaces: + - name: output + workspace: git-source + params: + - name: url + value: $(params.REPO_URL) + - name: revision + value: $(params.PULL_BASE_SHA) + - name: deleteExisting + value: "true" + - name: clippy + taskRef: + name: run-docker-image + workspaces: + - name: source + workspace: git-source + runAfter: + - fetch-repository + params: + - name: docker-image + value: "rustlang/rust:nightly-alpine3.17" + - name: command + value: + [ + cargo, + clippy, + --no-deps, + --all-targets, + --all-features, + --, + -D, + warnings, + ] + finally: + - name: report-success + when: + - input: "$(tasks.status)" + operator: in + values: ["Succeeded", "Completed"] + taskRef: + name: gitea-set-status + params: + - name: CONTEXT + value: "$(params.JOB_NAME)" + - name: REPO_FULL_NAME + value: "$(params.REPO_OWNER)/$(params.REPO_NAME)" + - name: GITEA_HOST_URL + value: code.fizz.buzz + - name: SHA + value: "$(tasks.fetch-repository.results.commit)" + - name: DESCRIPTION + value: "Build $(params.JOB_NAME) has succeeded" + - name: STATE + value: success + - name: TARGET_URL + value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)" + - name: report-failure + when: + - input: "$(tasks.status)" + operator: in + values: ["Failed"] + taskRef: + name: gitea-set-status + params: + - name: CONTEXT + value: "$(params.JOB_NAME)" + - name: REPO_FULL_NAME + value: "$(params.REPO_OWNER)/$(params.REPO_NAME)" + - name: GITEA_HOST_URL + value: code.fizz.buzz + - name: SHA + value: "$(tasks.fetch-repository.results.commit)" + - name: DESCRIPTION + value: "Build $(params.JOB_NAME) has failed" + - name: STATE + value: failure + - name: TARGET_URL + value: "https://tekton.fizz.buzz/#/namespaces/$(context.pipelineRun.namespace)/pipelineruns/$(context.pipelineRun.name)" + workspaces: + - name: git-source + - name: docker-credentials + workspaces: + - name: git-source + volumeClaimTemplate: + spec: + storageClassName: "nfs-client" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + subPath: rust-source + - name: cargo-cache + persistentVolumeClaim: + claimName: organic-cargo-cache-fmt + - name: docker-credentials + secret: + secretName: harbor-plain + serviceAccountName: build-bot + timeout: 240h0m0s + params: + - name: image-name + value: "harbor.fizz.buzz/private/organic-fmt" + - name: path-to-image-context + value: docker/cargo_fmt/ + - name: path-to-dockerfile + value: docker/cargo_fmt/Dockerfile diff --git a/.lighthouse/triggers.yaml b/.lighthouse/triggers.yaml index 521b20c6..b63e382b 100644 --- a/.lighthouse/triggers.yaml +++ b/.lighthouse/triggers.yaml @@ -30,3 +30,10 @@ spec: skip_branches: # We already run on every commit, so running when the semver tags get pushed is causing needless double-processing. - "^v[0-9]+\\.[0-9]+\\.[0-9]+$" + - name: clippy + source: "pipeline-clippy.yaml" + # Override https-based url from lighthouse events. + clone_uri: "git@code.fizz.buzz:talexander/organic.git" + skip_branches: + # We already run on every commit, so running when the semver tags get pushed is causing needless double-processing. + - "^v[0-9]+\\.[0-9]+\\.[0-9]+$" From 464685b52bec7caa0764833d486fb942eff7d822 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 19:27:15 -0400 Subject: [PATCH 2/5] Use a cargo cache for the clippy CI job. --- .lighthouse/pipeline-clippy.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.lighthouse/pipeline-clippy.yaml b/.lighthouse/pipeline-clippy.yaml index ab29a783..feae1aeb 100644 --- a/.lighthouse/pipeline-clippy.yaml +++ b/.lighthouse/pipeline-clippy.yaml @@ -79,6 +79,8 @@ spec: workspaces: - name: source workspace: git-source + - name: cargo-cache + workspace: cargo-cache runAfter: - fetch-repository params: @@ -157,7 +159,7 @@ spec: subPath: rust-source - name: cargo-cache persistentVolumeClaim: - claimName: organic-cargo-cache-fmt + claimName: organic-cargo-cache-clippy - name: docker-credentials secret: secretName: harbor-plain From d8e3a85ef76381b04e45779cab38ad95acafe692 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 19:34:53 -0400 Subject: [PATCH 3/5] We need to add dependencies so we are now building a container. --- .lighthouse/pipeline-clippy.yaml | 51 +++++++++++++++++++++----------- docker/organic_clippy/Dockerfile | 5 ++++ docker/organic_clippy/Makefile | 37 +++++++++++++++++++++++ 3 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 docker/organic_clippy/Dockerfile create mode 100644 docker/organic_clippy/Makefile diff --git a/.lighthouse/pipeline-clippy.yaml b/.lighthouse/pipeline-clippy.yaml index feae1aeb..99affd95 100644 --- a/.lighthouse/pipeline-clippy.yaml +++ b/.lighthouse/pipeline-clippy.yaml @@ -73,6 +73,35 @@ spec: value: $(params.PULL_BASE_SHA) - name: deleteExisting value: "true" + - name: build-image + taskRef: + name: kaniko + params: + - name: IMAGE + value: "$(params.image-name):$(tasks.fetch-repository.results.commit)" + - name: CONTEXT + value: $(params.path-to-image-context) + - name: DOCKERFILE + value: $(params.path-to-dockerfile) + - name: BUILDER_IMAGE + value: "gcr.io/kaniko-project/executor:v1.12.1" + - name: EXTRA_ARGS + value: + - --cache=true + - --cache-copy-layers + - --cache-repo=harbor.fizz.buzz/kanikocache/cache + - --use-new-run # Should result in a speed-up + - --reproducible # To remove timestamps so layer caching works. + - --snapshot-mode=redo + - --skip-unused-stages=true + - --registry-mirror=dockerhub.dockerhub.svc.cluster.local + workspaces: + - name: source + workspace: git-source + - name: dockerconfig + workspace: docker-credentials + runAfter: + - fetch-repository - name: clippy taskRef: name: run-docker-image @@ -82,22 +111,10 @@ spec: - name: cargo-cache workspace: cargo-cache runAfter: - - fetch-repository + - build-image params: - name: docker-image - value: "rustlang/rust:nightly-alpine3.17" - - name: command - value: - [ - cargo, - clippy, - --no-deps, - --all-targets, - --all-features, - --, - -D, - warnings, - ] + value: "$(params.image-name):$(tasks.fetch-repository.results.commit)" finally: - name: report-success when: @@ -167,8 +184,8 @@ spec: timeout: 240h0m0s params: - name: image-name - value: "harbor.fizz.buzz/private/organic-fmt" + value: "harbor.fizz.buzz/private/organic-clippy" - name: path-to-image-context - value: docker/cargo_fmt/ + value: docker/organic_clippy/ - name: path-to-dockerfile - value: docker/cargo_fmt/Dockerfile + value: docker/organic_clippy/Dockerfile diff --git a/docker/organic_clippy/Dockerfile b/docker/organic_clippy/Dockerfile new file mode 100644 index 00000000..a064450c --- /dev/null +++ b/docker/organic_clippy/Dockerfile @@ -0,0 +1,5 @@ +FROM rustlang/rust:nightly-alpine3.17 + +RUN apk add --no-cache musl-dev + +ENTRYPOINT ["cargo", "clippy", "--no-deps", "--all-targets", "--all-features", "--", "-D", "warnings"] diff --git a/docker/organic_clippy/Makefile b/docker/organic_clippy/Makefile new file mode 100644 index 00000000..9546365a --- /dev/null +++ b/docker/organic_clippy/Makefile @@ -0,0 +1,37 @@ +IMAGE_NAME:=organic-clippy +# REMOTE_REPO:=harbor.fizz.buzz/private + +.PHONY: all +all: build push + +.PHONY: build +build: + docker build -t $(IMAGE_NAME) -f Dockerfile . + +.PHONY: push +push: +ifdef REMOTE_REPO + docker tag $(IMAGE_NAME) $(REMOTE_REPO)/$(IMAGE_NAME) + docker push $(REMOTE_REPO)/$(IMAGE_NAME) +else + @echo "REMOTE_REPO not defined, not pushing to a remote repo." +endif + +.PHONY: clean +clean: + docker rmi $(IMAGE_NAME) +ifdef REMOTE_REPO + docker rmi $(REMOTE_REPO)/$(IMAGE_NAME) +else + @echo "REMOTE_REPO not defined, not removing from remote repo." +endif + docker volume rm cargo-cache + +# NOTE: This target will write to folders underneath the git-root +.PHONY: run +run: build + docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry $(IMAGE_NAME) + +.PHONY: shell +shell: build + docker run --rm -i -t --entrypoint /bin/sh --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry $(IMAGE_NAME) From e4d9c5f46738d55ce16bb74af624ec9bafa3e5aa Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 19:38:45 -0400 Subject: [PATCH 4/5] Add makefile command to run clippy through docker. --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 465127dc..afb961bc 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,10 @@ clean: format: > $(MAKE) -C docker/cargo_fmt run +.PHONY: dockerclippy +dockerclippy: +> $(MAKE) -C docker/organic_clippy run + .PHONY: clippy clippy: > cargo clippy --no-deps --all-targets --all-features -- -D warnings From e2d55e13d33c7e4bf4f6252ef369ca7ac3406329 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 16 Oct 2023 19:43:15 -0400 Subject: [PATCH 5/5] Fix some clippy errors that didn't appear on my host version of clippy. --- src/parser/latex_environment.rs | 11 +++-------- src/parser/line_break.rs | 2 +- src/parser/subscript_and_superscript.rs | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/parser/latex_environment.rs b/src/parser/latex_environment.rs index 11ccde2c..6503a66a 100644 --- a/src/parser/latex_environment.rs +++ b/src/parser/latex_environment.rs @@ -43,13 +43,8 @@ where let value_start = remaining; start_of_line(remaining)?; let (remaining, _leading_whitespace) = space0(remaining)?; - let (remaining, (_opening, name, _open_close_brace, _ws, _line_ending)) = tuple(( - tag_no_case(r#"\begin{"#), - name, - tag("}"), - space0, - line_ending, - ))(remaining)?; + let (remaining, (_opening, name, _open_close_brace, _ws, _line_ending)) = + tuple((tag_no_case(r"\begin{"), name, tag("}"), space0, line_ending))(remaining)?; let latex_environment_end_specialized = latex_environment_end(name.into()); let parser_context = ContextElement::ExitMatcherNode(ExitMatcherNode { @@ -127,7 +122,7 @@ fn _latex_environment_end<'b, 'g, 'r, 's, 'c>( start_of_line(input)?; let (remaining, _leading_whitespace) = space0(input)?; let (remaining, (_begin, _name, _close_brace, _ws, _line_ending)) = tuple(( - tag_no_case(r#"\end{"#), + tag_no_case(r"\end{"), tag_no_case(current_name_lower), tag("}"), space0, diff --git a/src/parser/line_break.rs b/src/parser/line_break.rs index 1d460f3d..fef89405 100644 --- a/src/parser/line_break.rs +++ b/src/parser/line_break.rs @@ -21,7 +21,7 @@ pub(crate) fn line_break<'b, 'g, 'r, 's>( input: OrgSource<'s>, ) -> Res, LineBreak<'s>> { let (remaining, _) = pre(context, input)?; - let (remaining, _) = tag(r#"\\"#)(remaining)?; + let (remaining, _) = tag(r"\\")(remaining)?; let (remaining, _) = recognize(many0(one_of(" \t")))(remaining)?; let (remaining, _) = line_ending(remaining)?; let source = get_consumed(input, remaining); diff --git a/src/parser/subscript_and_superscript.rs b/src/parser/subscript_and_superscript.rs index 64ebc7f0..0851ea74 100644 --- a/src/parser/subscript_and_superscript.rs +++ b/src/parser/subscript_and_superscript.rs @@ -175,7 +175,7 @@ fn script_alphanum<'b, 'g, 'r, 's>( #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] fn script_alphanum_character<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { recognize(verify(anychar, |c| { - c.is_alphanumeric() || r#",.\"#.contains(*c) + c.is_alphanumeric() || r",.\".contains(*c) }))(input) } @@ -183,7 +183,7 @@ fn script_alphanum_character<'s>(input: OrgSource<'s>) -> Res, Org fn end_script_alphanum_character<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> { let (remaining, final_char) = recognize(verify(anychar, |c| c.is_alphanumeric()))(input)?; peek(tuple(( - take_while(|c| r#",.\"#.contains(c)), + take_while(|c| r",.\".contains(c)), not(script_alphanum_character), )))(remaining)?; Ok((remaining, final_char))