Auto Update Golang Version #47
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
name: Auto Update Golang Version | |
permissions: write-all | |
on: | |
schedule: | |
# each day | |
- cron: "0 20 * * *" | |
workflow_dispatch: | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: update golang version | |
run: | | |
cat /etc/os-release | |
latest_version=$(curl -s https://go.dev/dl/ | grep -oP 'go[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -n 1 | grep -oP '[0-9]+\.[0-9]+\.[0-9]+') | |
echo "latest_version: $latest_version" | |
project_version=$(cat GO_VERSION | grep -oP '[0-9]+\.[0-9]+\.[0-9]+') | |
echo "project_version: $project_version" | |
[ "$latest_version" != "$project_version" ] || { | |
echo " golang version is latest" | |
echo "RUN_UPDATE=false" >> $GITHUB_ENV | |
exit 0 | |
} | |
echo "${latest_version}" > GO_VERSION | |
cat GO_VERSION | |
make update_go_version -e GO_VERSION=${latest_version} | |
git status | |
git diff | |
if ! test -z "$$(git status --porcelain)"; then | |
echo "update golang" | |
echo "RUN_UPDATE=true" >> $GITHUB_ENV | |
echo "GO_VERSION=${latest_version}" >> $GITHUB_ENV | |
else | |
echo "no need to update golang version" | |
echo "RUN_UPDATE=false" >> $GITHUB_ENV | |
fi | |
# https://github.com/peter-evans/create-pull-request | |
- name: Create Pull Request | |
id: create_pr | |
if: ${{ env.RUN_UPDATE == 'true' }} | |
uses: peter-evans/[email protected] | |
with: | |
title: "robot updates Golang Version to ${{ env.GO_VERSION }}" | |
commit-message: "robot Update project owing to updated Golang Version " | |
branch-suffix: timestamp | |
branch: robot/update_golang | |
delete-branch: true | |
base: main | |
signoff: true | |
token: ${{ secrets.WELAN_PAT }} | |
labels: pr/robot_update |