Run Gofmt and Goimport #1757
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2021 The Knative Authors. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# 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. | |
## | |
## This file is auto-generated from actions/update-gofmt/auto-apply.yaml | |
## by ./cmd/gen-actions | |
## | |
name: Run Gofmt and Goimport | |
on: | |
schedule: | |
- cron: '0 1,13 * * 1-5' # 6am/pm Pacific on weekdays | |
workflow_dispatch: | |
inputs: | |
only-repo: | |
description: "Only autogenerate a single repo (exact match)?" | |
reason: | |
description: "Justification?" | |
required: true | |
jobs: | |
meta: | |
runs-on: ubuntu-latest | |
outputs: | |
includes: ${{ steps.load-matrix.outputs.includes }} | |
names: ${{ steps.load-matrix.outputs.names }} | |
steps: | |
- name: Check out knobots configuration | |
uses: actions/checkout@v4 | |
- name: Calculate affected repos | |
id: load-matrix | |
uses: "./actions/calculate-matrix" | |
with: | |
action-name: gofmt | |
only-repo: ${{ github.event.inputs.only-repo }} | |
apply-change: | |
name: "Apply Change" # TODO: from metadata? | |
needs: meta | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
max-parallel: 5 | |
matrix: | |
name: ${{ fromJson(needs.meta.outputs.names) }} | |
include: ${{ fromJson(needs.meta.outputs.includes) }} | |
steps: | |
- name: Checkout config code | |
uses: actions/checkout@v4 | |
with: | |
path: config | |
- name: Checkout ${{ matrix.name }} code | |
uses: actions/checkout@v4 | |
with: | |
path: main | |
repository: ${{ matrix.name }} | |
# This is required because the branch setting might be empty (to infer a default), so | |
# after checkout we fetch what the checkout action decided to check out. | |
- name: Infer branch from checkout | |
id: inferbranch | |
run: | | |
cd main | |
echo "branch=$(git branch --show-current)" >> $GITHUB_OUTPUT | |
- name: Apply work | |
id: work | |
uses: "./config/actions/update-gofmt" | |
with: | |
repo: ${{ matrix.name }} | |
organization: ${{ matrix.meta-organization }} | |
include: ${{ matrix.include }} | |
- name: Create Pull Request | |
id: cpr | |
if: ${{ env.create_pr == 'true' }} | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
# Who to look like | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
committer: "Knative Automation <[email protected]>" | |
author: "Knative Automation <[email protected]>" | |
# Where to stage the change | |
push-to-fork: ${{ matrix.fork }} | |
branch: auto-updates/update-gofmt-${{ steps.inferbranch.outputs.branch }} | |
signoff: true | |
delete-branch: true | |
# What labels to add | |
labels: ${{ env.pr_labels }} | |
# Note this is hard-coded based on the added repos in main.go | |
path: main | |
commit-message: | | |
Format go code | |
${{ steps.work.outputs.log }} | |
title: "[${{ steps.inferbranch.outputs.branch }}] Format Go code" | |
body: | | |
${{ github.event.inputs.reason || 'Cron' }} -${{ github.actor }} | |
/cc ${{ matrix.assignees }} | |
/assign ${{ matrix.assignees }} | |
Produced by: ${{ github.repository }}/actions/update-gofmt | |
Details: | |
``` | |
${{ steps.work.outputs.log }} | |
``` | |
- name: Report error | |
uses: rtCamp/action-slack-notify@v2 | |
if: ${{ failure() }} | |
env: | |
SLACK_ICON: http://github.com/knative-automation.png?size=48 | |
SLACK_USERNAME: knative-automation | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: ${{ matrix.channel }} | |
SLACK_COLOR: '#8E1600' | |
MSG_MINIMAL: 'true' | |
SLACK_TITLE: "[${{ steps.inferbranch.outputs.branch }}] Format Go code for ${{ matrix.name }} failed." | |
SLACK_MESSAGE: | | |
For detailed logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
${{ github.event.inputs.reason || 'Cron' }} -${{ github.actor }} |