Skip to content

Commit

Permalink
ci: improve import path action (#2104)
Browse files Browse the repository at this point in the history
(cherry picked from commit dcc82d7)

# Conflicts:
#	.github/workflows/import_paths.yml
#	scripts/replace_import_paths.sh
  • Loading branch information
p0mvn authored and mergify[bot] committed Aug 13, 2022
1 parent 2a45d28 commit 75d4295
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/import_paths.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This is a manua workflow that does the following when trigerred:
# - Runs a script to find and replace Go import path major version with given version.
# - Commits and pushes changes to the source-branch.
# - Opens a PR from the source branch to the target-branch.

name: Update Go Import Paths

on:
workflow_dispatch:
inputs:
version:
description: 'Current Version that we want to change'
default: '10'
required: true
target-branch:
description: 'Target Branch'
default: 'main'
required: true
source-branch:
description: 'Source Branch'
default: 'update-paths'
required: true

jobs:
update-import-paths:
runs-on: ubuntu-latest

steps:
-
name: Check out repository code
uses: actions/checkout@v2
-
name: Setup Golang
uses: actions/[email protected]
with:
go-version: 1.18
-
name: Display go version
run: go version
-
name: Get data from build cache
uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
-
name: Run find & replace script
run: ./scripts/replace_import_paths.sh ${{ inputs.version }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.ADD_TO_PROJECT_PAT }}
title: "auto: update Go import paths to v${{ inputs.version }}"
commit-message: "auto: update Go import paths to v${{ inputs.version }}"
body: "**Automated pull request**\n\nUpdating Go import paths to v${{ inputs.version }}"
base: ${{ inputs.target-branch }}
branch-suffix: random
branch: ${{ inputs.source-branch }}
delete-branch: true
assignees: ${{ github.actor }}
draft: true
labels: T:auto,T:code-hygiene
28 changes: 28 additions & 0 deletions scripts/replace_import_paths.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ replace_paths() {
sed -i "s/github.com\/osmosis-labs\/osmosis\/v${version_to_replace}/github.com\/osmosis-labs\/osmosis\/v${NEXT_MAJOR_VERSION}/g" ${file}
}

<<<<<<< HEAD
echo "Replacing import paths in all files"

files=$(find ./ -type f -and -not \( -path "./vendor*" -or -path "./.git*" -or -name "*.md" \))
Expand All @@ -26,14 +27,41 @@ for file in $files; do
replace_paths ${file}
done

=======
echo "Replacing import paths in Go files"
for mod in $modules;
do
for file in $mod/*; do
if [ -f "${file}" ]; then
replace_paths $file
fi
done
done

echo "Replacing import paths in proto files"
for file in $(find proto/osmosis -type f -name "*.proto"); do
replace_paths $file
done

# protocgen.sh
replace_paths "scripts/protocgen.sh"

>>>>>>> dcc82d72 (ci: improve import path action (#2104))
echo "Updating go.mod and vendoring"
# go.mod
replace_paths "go.mod"
go mod vendor >/dev/null

<<<<<<< HEAD
# ensure that generated files are updated.
# N.B.: This must be run after go mod vendor.
echo "running make proto-gen"
make proto-gen >/dev/null
echo "running make run-querygen"
make run-querygen >/dev/null
=======
echo "running make proto-gen"
# ensure protos match generated Go files
# N.B.: This must be run after go mod vendor.
make proto-gen >/dev/null
>>>>>>> dcc82d72 (ci: improve import path action (#2104))

0 comments on commit 75d4295

Please sign in to comment.