-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
87 lines (83 loc) · 2.92 KB
/
action.yaml
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
name: Create or update PR
description: 'A simple but powerful GitHub Action to link workflows and manage dependencies between projects. #actionshackathon21'
author: 'shiipou'
inputs:
name:
description: 'The PR name to update or create'
required: true
type: string
message:
description: 'The message to post on PR after creation'
required: true
type: string
script:
description: 'Commands you want to execute before creation or update of the new PR'
required: true
type: string
token:
description: 'The GitHub Token to call GitHub API'
required: true
type: string
runs:
using: "composite"
steps:
- name: GitHub authentification
shell: bash
run: |
# Login into GitHub API
gh auth login --with-token < <(echo "${{ inputs.token }}")
# Set bot name to allow push
git config user.email "github-bot@nocturlab.fr"
git config user.name "GitHub Bot"
- name: Switch Git user
uses: actions/checkout@v2
with:
token: ${{ inputs.token }}
- name: Get PR infos
id: get-pr-info
shell: bash
run: |
# Find PR that use the generated name branch as head.
branch="$(echo "deps-bot/${{ inputs.name }}" | tr '[:upper:]' '[:lower:]')"
branch=${branch// /-}
echo "::set-output name=branch::${branch}"
_id=$(gh pr list -H "${branch}" | cut -f1)
_label=$(gh pr list -H "${branch}" | cut -f2)
if [ -n "${_id}" ]; then
echo "::set-output name=id::${_id}"
echo "::set-output name=pr::${_label}"
fi
- name: Create new git branch
if: steps.get-pr-info.outputs.id == ''
shell: bash
run: |
# If PR not exist, create a new branch
branch="${{ steps.get-pr-info.outputs.branch }}"
git checkout -b "${branch}"
- name: Checkout
if: steps.get-pr-info.outputs.id != ''
shell: bash
run: |
# If PR Already exist, rebase to main branch and switch to ${{ steps.get-pr-info.outputs.branch }}
git fetch
git checkout "${{ steps.get-pr-info.outputs.branch }}"
- name: Run script
shell: bash
run: |
# Run the script that edit the files we need
set -xe
${{ inputs.script }}
- name: Push new changes
shell: bash
run: |
# Set debug mode to show logs from the script inside of runnign workflow's logs
set -xe
# Push the changement to the PR branch using the correct method (PR already exist or not)
if [ -n "${{ steps.get-pr-info.outputs.id }}" ]; then
id="${{ steps.get-pr-info.outputs.id }}"
git push --force
gh pr comment "$id" --body "${{ github.event.inputs.message }}"
else
git push -u origin "${{ steps.get-pr-info.outputs.branch }}"
gh pr create --title "${{ inputs.name }}" --body "${{ github.event.inputs.message }}"
fi