-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
110 lines (100 loc) · 3.45 KB
/
action.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
100
101
102
103
104
105
106
107
108
109
110
name: 'Bot'
description: 'Fetch dependencies (zig modules & git clone used in build.zig) & makes a pull request'
inputs:
repository:
description: 'The repository name'
required: true
token:
description: 'The github token'
required: true
runs:
using: "composite"
steps:
- uses: tiawl/[email protected]
- uses: tiawl/[email protected]
with:
repository: "${{ github.repository }}"
path: "${{ github.action_path }}"
- uses: actions/checkout@v4
with:
repository: "${{ inputs.repository }}"
- name: Close every bot PRs
env:
OPTIONS: "--author '@me' --state open --json \"${{ env.gh_field }}\""
COMMENT: "--comment '${{ env.gh_bot_close_comment }}'"
GH_TOKEN: "${{ inputs.token }}"
FILTER: ".[] | .${{ env.gh_field }}"
shell: ${{ env.shell }}
run: |
declare -a pr_list=( $(gh pr list ${OPTIONS} | jq "${FILTER}") )
for pr_nr in ${pr_list[@]}
do gh pr close "${pr_nr}" ${COMMENT} --delete-branch; done
if [[ "$(gh pr list ${OPTIONS} | jq length)" != '0' ]]
then exit 1; fi
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: ${{ env.zig_version }}
- name: Install apt packages
if: runner.os == 'LINUX'
env:
PACKAGES: "${{ env.apt_packages }}"
shell: ${{ env.shell }}
run: |
sudo apt-get install -y ${PACKAGES}
printf 'ACTIVATE_DIR=bin\n' >> "${GITHUB_ENV}"
- name: Activate python virtual env & install pip packages
env:
PACKAGES: "${{ env.pip_packages }}"
RUNNER_TMP: "${{ runner.temp }}"
shell: ${{ env.shell }}
run: |
python3 -m venv "${RUNNER_TMP}/venv"
source "${RUNNER_TMP}/venv/${ACTIVATE_DIR:-Scripts}/activate"
pip install ${PACKAGES}
- name: Setup git user information
env:
BRANCH: "${{ env.bot_branch }}"
EMAIL: "${{ env.gh_bot_email }}"
NAME: "${{ env.gh_bot_name }}"
shell: ${{ env.shell }}
run: |
git config user.name "${NAME}"
git config user.email "${EMAIL}"
git checkout -b "${BRANCH}"
- name: Fetch
id: fetch
env:
RUNNER_TMP: "${{ runner.temp }}"
shell: ${{ env.shell }}
run: |
source "${RUNNER_TMP}/venv/${ACTIVATE_DIR:-Scripts}/activate"
zig build -Dfetch
- name: Diff
if: steps.fetch.conclusion == 'success'
id: diff
shell: ${{ env.shell }}
run: |
diffs="$(git diff HEAD --name-only | wc -l)"
printf 'len=%s\n' "${diffs}" >> "${GITHUB_OUTPUT}"
- name: Update
if: steps.fetch.conclusion == 'success' && steps.diff.outputs.len != '0'
env:
RUNNER_TMP: "${{ runner.temp }}"
shell: ${{ env.shell }}
run: |
source "${RUNNER_TMP}/venv/${ACTIVATE_DIR:-Scripts}/activate"
zig build -Dupdate
- name: Create Pull Request
if: steps.fetch.conclusion == 'success' && steps.diff.outputs.len != '0' && inputs.repository == github.repository
env:
BRANCH: "${{ env.bot_branch }}"
DEFAULT: "${{ env.default_branch }}"
GH_TOKEN: "${{ inputs.token }}"
TITLE: "${{ env.gh_bot_pr_title }}"
shell: ${{ env.shell }}
run: |
git add -A
git commit -m "Bot: ${TITLE}"
git push --force --set-upstream origin "${BRANCH}"
gh pr create --base "${DEFAULT}" --fill --reviewer "${GITHUB_REPOSITORY_OWNER}"