Update go packages dependencies versions #390
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: Update go packages dependencies versions | |
# Set jobs to be configured and executed by schedule. | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'release-2.7' | |
- 'release-2.6' | |
schedule: | |
- cron: '0 6 * * 1-5' # Actions will be executed at 6am for every weekday. | |
# Set environment variables. | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
main: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v2 | |
- name: Setup go for repository code | |
uses: actions/setup-go@v2 | |
with: | |
go-version: '1.21' | |
- name: Validate installed go version | |
run: | | |
echo "Using go version: $(go version)" | |
- name: Create log entry for github action results | |
run: | | |
mkdir -p .github/logs | |
echo -e "### Generated logs from GitHub Action: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n" >> .github/logs/update-log-$(date +%m-%d-%y).md | |
- name: Add updated log entry report to README # Once the PR has been merged, the link will be active and available for view. | |
run: | | |
echo -e "\nGenerated auto rebuild. View log file created: [update-log-$(date +%m-%d-%y)](https://github.com/stolostron/multicluster-observability-operator/blob/main/.github/logs/update-log-$(date +%m-%d-%y).md)" >> README.md | |
- name: Verify outdated go modules dependencies versions | |
id: outdated | |
continue-on-error: true # Continuing on error, we need to check for outdated modules, so it's okay for this step to fail. | |
run: | | |
echo "Preparing to list outdated go modules versions within current build" | |
go list -u -m all | |
- name: Update go modules dependencies to latest versions | |
id: updated | |
continue-on-error: true # Continuing on error, adding this for debugging purposes. | |
run: | | |
echo "Preparing to update all go modules dependencies to latest versions" | |
go get -u all >> .github/logs/update-log-$(date +%m-%d-%y).md 2>&1 | |
go mod tidy | |
- name: Update log file format | |
id: format-log | |
continue-on-error: true | |
run: | | |
sed -i 's/^go:/- go:/g; s/^go get/- go get/g' .github/logs/update-log-$(date +%m-%d-%y).md | |
- name: Verify go modules dependencies updated to latest versions (failure) | |
id: verify-failure | |
if: steps.updated.outcome == 'failure' | |
run: | | |
echo -e "\n#### Failed to update the outdated go modules dependencies successfully. Manual updating is needed to resolve the dependecies issue.\n---" >> .github/logs/update-log-$(date +%m-%d-%y).md | |
- name: Verify go modules dependencies updated to latest versions (success) | |
id: verify-success | |
if: steps.updated.outcome == 'success' | |
run: | | |
echo -e "\n#### Successfully updated the go modules dependencies.\n---" >> .github/logs/update-log-$(date +%m-%d-%y).md | |
- name: Validate package build properly | |
run: | | |
echo "Preparing to build package" | |
go build ./... | |
- name: Check modified files | |
run: | | |
git status | |
- name: Create pull request for updated node modules versions | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
add-paths: . | |
body: | | |
This PR is auto-generated by the Git action [go-package-dependencies-update](https://github.com/stolostron/multicluster-observability-operator/blob/main/.github/workflows/go-package-dependencies-update.yml). | |
branch-suffix: short-commit-hash | |
commit-message: 'Updated go module versions within the project' | |
delete-branch: true | |
labels: automated-pr | |
# reviewers: TBD | |
signoff: true | |
title: '[Automated PR] Updated go modules versions within the project' | |
token: ${{ secrets.GITHUB_TOKEN }} |