From fff6843da0acae8f2a9ddaa3d14e471ab61ec37b Mon Sep 17 00:00:00 2001 From: Albin Vass Date: Mon, 27 Apr 2020 20:47:07 +0200 Subject: [PATCH] go: Use 'block: ... always: ...' and failed_when instead of ignore_errors Change-Id: I11fc6ec69eda00f4ac824f27712acc82ec445f79 --- roles/ensure-go/tasks/main.yaml | 2 +- roles/golangci-lint/tasks/main.yaml | 46 +++++++++++++---------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/roles/ensure-go/tasks/main.yaml b/roles/ensure-go/tasks/main.yaml index e4936ec3d..2ce6f5ef3 100644 --- a/roles/ensure-go/tasks/main.yaml +++ b/roles/ensure-go/tasks/main.yaml @@ -3,7 +3,7 @@ register: go_installed_version environment: PATH: "{{ ansible_env.PATH }}:{{ go_install_dir }}/go/bin" - ignore_errors: yes + failed_when: false - name: Skip if correct version of go is installed include_tasks: install-go.yaml diff --git a/roles/golangci-lint/tasks/main.yaml b/roles/golangci-lint/tasks/main.yaml index 7f90a4598..1e55d3773 100644 --- a/roles/golangci-lint/tasks/main.yaml +++ b/roles/golangci-lint/tasks/main.yaml @@ -1,27 +1,23 @@ -- name: Run golangci-lint - command: "golangci-lint run {{ golangci_lint_options }}" - args: - chdir: "{{ zuul_work_dir }}" - environment: - PATH: "{{ ansible_env.PATH }}:{{ go_bin_path }}" - ignore_errors: true - register: _golangci_lint +- block: + - name: Run golangci-lint + command: "golangci-lint run {{ golangci_lint_options }}" + args: + chdir: "{{ zuul_work_dir }}" + environment: + PATH: "{{ ansible_env.PATH }}:{{ go_bin_path }}" + register: _golangci_lint -- name: Look for output - golangci_lint_parse_output: - workdir: '{{ zuul_work_dir }}' - output: '{{ _golangci_lint.stdout }}' - register: _golangci_lint_parse_output + always: + - name: Look for output + golangci_lint_parse_output: + workdir: '{{ zuul_work_dir }}' + output: '{{ _golangci_lint.stdout }}' + register: _golangci_lint_parse_output -- name: Return file comments to Zuul - when: _golangci_lint_parse_output.comments - delegate_to: localhost - zuul_return: - data: - zuul: - file_comments: '{{ _golangci_lint_parse_output.comments }}' - -- name: Return golangci-lint status - fail: - msg: 'golangci-lint exited with return code {{ _golangci_lint.rc }}' - when: _golangci_lint.rc != 0 + - name: Return file comments to Zuul + when: _golangci_lint_parse_output.comments + delegate_to: localhost + zuul_return: + data: + zuul: + file_comments: '{{ _golangci_lint_parse_output.comments }}'