Skip to content

Automated go get update #68

Automated go get update

Automated go get update #68

name: Automated go get update
on:
issue_comment:
types:
- created
push:
branches:
- main
paths:
- go.mod
- go.sum
schedule:
- cron: 58 4 * * *
workflow_dispatch: {}
permissions:
contents: write
pull-requests: write
jobs:
go-get-update:
name: go get update
runs-on: ubuntu-24.04
environment: automated
if: >-
github.event_name != 'issue_comment' ||
contains(github.event.comment.body, '/rerun')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Go get update
run: |
go get -u 2>&1 | tee .github/update.log
if [[ -s .github/update.log ]]; then
go mod tidy -v 2>&1 | tee -a .github/update.log
fi
sed -e 's/\x1b\[[0-9;]*m//g' -e 's/^go: /- /' .github/update.log > .github/pr_body.log
- name: Check for changes
run: |
if git diff --exit-code; then
echo "changes=false" >> $GITHUB_ENV
else
echo "changes=true" >> $GITHUB_ENV
fi
- name: Commit and push to branch
if: env.changes == 'true'
uses: EndBug/add-and-commit@v9
with:
github_token: ${{ secrets.GH_TOKEN }}
default_author: github_actions
message: Automated go get update
new_branch: automated/go-get-update
fetch: false
push: origin automated/go-get-update --set-upstream --force
- name: Create pull request
id: pr
if: env.changes == 'true'
uses: devops-infra/action-pull-request@master
with:
github_token: ${{ secrets.GH_TOKEN }}
target_branch: main
label: automated
title: Automated go get update
get_diff: false
- name: Update pull request description
if: env.changes == 'true'
run: gh pr edit ${{ steps.pr.outputs.pr_number }} --body-file .github/pr_body.log
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Close pull request
if: env.changes == 'false'
run: gh pr list --head automated/go-get-update --json number --jq '.[].number' | xargs -rn1 gh pr close --delete-branch
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}