forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (96 loc) · 3.61 KB
/
go-get.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Go get
on:
workflow_dispatch:
inputs:
goget_module:
type: string
description: "What Go module to get"
goget_version:
type: string
description: "What Go module version to get"
source_url:
type: string
description: "URL of the source for this workflow run"
source_author:
type: string
description: "Username of the source for this workflow run"
env:
GOGET_MODULE: ${{ github.event.inputs.goget_module }}
GOGET_VERSION: ${{ github.event.inputs.goget_version }}
INPUT_SOURCE_URL: ${{ github.event.inputs.source_url }}
INPUT_SOURCE_AUTHOR: ${{ github.event.inputs.source_author }}
permissions:
contents: write
pull-requests: write
jobs:
go-get:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Run go get to get Go module
run: make go-get
- name: Check for repository changes
run: |
if git diff --name-only --exit-code; then
echo "No changes found in repository after 'go get'"
echo "changes_exist=false" >> $GITHUB_ENV
else
echo "Changes found in repository after 'go get':"
git diff --name-only
echo "changes_exist=true" >> $GITHUB_ENV
fi
- name: Create branch, commit and push
if: ${{ env.changes_exist == 'true' }}
id: branch
run: |
BRANCH="githubaction-go-get-$(date +%Y-%m-%d-%H-%M-%S)"
echo "::set-output name=branch::$BRANCH"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git checkout -b "$BRANCH"
git commit -a -m "go get ${GOGET_MODULE} ${GOGET_VERSION}"
git push origin "$BRANCH"
- name: Create Pull Request
if: ${{ env.changes_exist == 'true' }}
id: cpr
uses: actions/[email protected]
env:
SOURCE_BRANCH: ${{ steps.branch.outputs.branch }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { GOGET_MODULE, GOGET_VERSION} = process.env
let body = 'Auto-generated by GitHub Actions\n\n'
if ( `${ process.env.INPUT_SOURCE_URL }` ) {
body += `\nSource URL: ${ process.env.INPUT_SOURCE_URL }`
}
if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) {
body += `\nSource AUTHOR: @${ process.env.INPUT_SOURCE_AUTHOR}`
}
const { data: pr } = await github.rest.pulls.create({
title: `[${{ github.ref_name }}] go get ${GOGET_MODULE} ${GOGET_VERSION}`,
body: body,
owner: context.repo.owner,
repo: context.repo.repo,
base: "${{ github.ref_name }}",
head: `${ process.env.SOURCE_BRANCH }`
});
await github.rest.issues.addLabels({
...context.repo,
issue_number: pr.number,
labels: ["status/auto-created"],
});
if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) {
await github.rest.issues.addAssignees({
...context.repo,
issue_number: pr.number,
assignees: [`${ process.env.INPUT_SOURCE_AUTHOR}`],
});
}
console.log('Created new pull request');
return pr.html_url;
- name: Check outputs
if: ${{ env.changes_exist == 'true' }}
run: |
echo "Pull Request URL - ${{ steps.cpr.outputs.result }}"