Update dependent repositories #18473
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 dependent repositories | |
on: | |
workflow_run: | |
types: | |
- completed | |
workflows: | |
- 'Update references' | |
jobs: | |
update-dependent-repositories: | |
strategy: | |
matrix: | |
repository: | |
- integration-tests | |
name: Update ${{ matrix.repository }} | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.23.3 | |
- name: Setup envs | |
run: | | |
echo GOPATH=$GITHUB_WORKSPACE >> $GITHUB_ENV | |
echo GO111MODULE=on >> $GITHUB_ENV | |
echo $GITHUB_WORKSPACE/bin >> $GITHUB_PATH | |
- name: Checkout ${{ github.repository }} | |
uses: actions/checkout@v2 | |
with: | |
path: ${{ github.workspace }}/src/github.com/${{ github.repository }} | |
repository: ${{ github.repository }} | |
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} | |
fetch-depth: 2 | |
- name: Install gotestmd | |
run: | | |
go install github.com/networkservicemesh/gotestmd@main | |
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }} | |
- name: Install goimports | |
run: | | |
go install golang.org/x/tools/cmd/goimports@v0.16.1 | |
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }} | |
- name: Get hash of PR commit | |
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }} | |
id: get-pr-hash | |
run: | | |
echo '::set-output name=hash::'$(git rev-parse HEAD^) | |
- name: Find merged PR | |
uses: jwalton/gh-find-current-pr@v1.0.2 | |
id: findPr | |
with: | |
sha: ${{ steps.get-pr-hash.outputs.hash }} | |
github-token: ${{ github.token }} | |
- name: Checkout networkservicemesh/${{ matrix.repository }} | |
uses: actions/checkout@v2 | |
with: | |
path: ${{ github.workspace }}/src/github.com/networkservicemesh/${{ matrix.repository }} | |
repository: networkservicemesh/${{ matrix.repository }} | |
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} | |
- name: Update ${{ matrix.repository }} locally | |
working-directory: ${{ github.workspace }}/src/github.com/networkservicemesh/${{ matrix.repository }} | |
run: | | |
go generate | |
go mod tidy | |
- name: Push update to the ${{ matrix.repository }} | |
working-directory: ${{ github.workspace }}/src/github.com/networkservicemesh/${{ matrix.repository }} | |
run: | | |
sed -r -i 's/sha = "[a-z0-9]*"/sha = "${{ github.sha }}"/g' extensions/base/suite.gen.go | |
echo Starting to update repositotry ${{ matrix.repository }} | |
git config --global user.email "nsmbot@networkservicmesh.io" | |
git config --global user.name "NSMBot" | |
git add -- . | |
if ! [ -n "$(git diff --cached --exit-code)" ]; then | |
echo ${{ matrix.repository }} is up to date | |
exit 0; | |
fi | |
echo "Update go.mod and go.sum to latest version from ${{ github.repository }}@main" >> /tmp/commit-message | |
echo "PR link: https://github.com/${{ github.repository }}/pull/${{ steps.findPr.outputs.pr }}" >> /tmp/commit-message | |
echo "" >> /tmp/commit-message | |
LOG_MSG=$(git log --date=iso --pretty='format:Commit: %h%nAuthor: %an%nDate: %ad%nMessage:%n - %B%n' -1 | sed '/^$/d;$d') | |
for((i=2;i<=18;i+=2)); do n=$(printf '%*s' $((i+2))) m=$(printf '%*s' $i) LOG_MSG=$(echo "$LOG_MSG" | tr '\n' '|' | sed "s/${m}-/${n}-/2g" | tr '|' '\n'); done | |
echo "$LOG_MSG" >> /tmp/commit-message | |
echo "Commit Message:" | |
cat /tmp/commit-message | |
git commit -s -F /tmp/commit-message | |
git checkout -b update/${{ github.repository }} | |
git push -f origin update/${{ github.repository }} |