-
-
Notifications
You must be signed in to change notification settings - Fork 6
69 lines (58 loc) · 2.5 KB
/
import.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: import upstream
on:
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:
permissions: write-all
jobs:
import:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- id: tools
run: |
# Clone the repository to a temporary directory.
tools=$(mktemp -d)/tools
git clone --depth 1 "https://github.com/golang/tools" "$tools"
echo "tools=$tools" >> $GITHUB_ENV
# Copy the diff package to the current directory.
cp -r "$tools/internal/diff/"* .
# Replace the import path.
find . -type f -name '*.go' -exec sed -i'' 's|golang.org/x/tools/internal/diff/|github.com/aymanbagabas/go-udiff/|g' {} +
find . -type f -name '*.go' -exec sed -i'' 's|"golang.org/x/tools/internal/diff|diff "github.com/aymanbagabas/go-udiff|g' {} +
# Change package name to udiff.
sed -i'' 's|package diff|package udiff|g' *.go
# Apply patches
for p in _patches/*; do
git apply $p
done
# Set output variables.
echo "base=$(cat .github/UPSTREAM | head -n1)" >> $GITHUB_OUTPUT
cd "$tools"
commit=$(git rev-parse HEAD)
echo "commit=$commit" >> $GITHUB_OUTPUT
cd -
# Update the upstream commit.
if ! git update-index --refresh || ! git diff-index --quiet HEAD --; then
echo "$commit" > .github/UPSTREAM
fi
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v5
with:
commit-message: "feat: import upstream package"
title: "Import upstream package [create-pull-request]"
body: |
Import upstream changes from [tree](https://github.com/golang/tools/tree/${{ steps.tools.outputs.commit }}/internal/diff).
Take a look at the [diff](https://github.com/golang/tools/commits/master/internal/diff) to see what changed.
branch: "import-upstream"
delete-branch: true
- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json