-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
119 lines (103 loc) · 4.44 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
111
112
113
114
115
116
117
118
119
name: 'WIPAC Dev Py Dependencies'
description: 'GitHub Action Package for Automating Python-Package Dependency Management'
inputs:
git_committer_name:
description: 'The name used for "git config user.name"'
required: false
default: github-actions
git_committer_email:
description: 'The email used for "git config user.email"'
required: false
default: [email protected]
docker_tag_to_dep:
description: 'The email used for "git config user.email"'
required: false
default: py-dep-this
use_directory:
description: 'Whether to put all generated dep-log files, relative to the project/repo directory; (true/false)'
required: false
default: "false"
# outputs:
# random-number:
# description: "Random number"
# value: ${{ steps.random-number-generator.outputs.random-id }}
runs:
using: "composite"
steps:
- uses: actions/setup-python@v4
with:
python-version: '3.11' # NOTE: update, someday. Also tests.yml
- name: Is this the most recent commit? It won't be if the action was reran
run: |
# check git status
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
git fetch &> /dev/null
if [[ $(git status -sb | grep behind) ]]; then
echo "IS_GIT_BEHIND=true" >> $GITHUB_ENV
echo "this commit is not the most recent on this branch -- rest of action will be skipped"
fi
shell: bash
- name: Git config
if: env.IS_GIT_BEHIND != 'true'
run: |
# git config
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
git config user.name ${{ inputs.git_committer_name }}
git config user.email ${{ inputs.git_committer_email }}
shell: bash
- name: pip
if: env.IS_GIT_BEHIND != 'true'
run: |
sudo apt-get update
pip3 install -r ${{ github.action_path }}/requirements.txt
shell: bash
- name: Build dependencies.log (and commit)
if: env.IS_GIT_BEHIND != 'true'
env:
ACTION_REPOSITORY: ${{ github.action_repository }} # https://github.com/github/docs/issues/25336#issuecomment-1736251764
GITHUB_ACTION_PATH: ${{ github.action_path }}
DOCKER_TAG_TO_DEP: ${{ inputs.docker_tag_to_dep }}
DEST_DIRECTORY_IF_WANTED: dependencies-logs/
run: |
# build dependencies.log (and commit)
set +x; echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; set -x
# append permissive line to .gitignore since *.log is commonly present
line='!dependencies*.log'
if [[ ! $(grep -F "$line" .gitignore) ]]; then
echo "" >> .gitignore
echo "" >> .gitignore
echo "# wipac-dev-py-setup-action" >> .gitignore
echo "$line" >> .gitignore
git add .gitignore
git commit -m "<bot> update .gitignore" || true # okay if no change
tail .gitignore
fi
set +x; echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; set -x
# remove any old ones, then regenerate only what's needed
(find . -name "dependencies*.log" -type f -print0 | xargs -0 rm) || true
# run script
export REPO_PATH=$(pwd)
/bin/bash $GITHUB_ACTION_PATH/action.sh
set +x; echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; set -x
if [[ $( echo "${{ inputs.use_directory }}" | awk '{print tolower($0)}' ) == "true" ]]; then
mkdir -p $DEST_DIRECTORY_IF_WANTED
find . -name "dependencies*.log" -type f -exec mv -i {} $DEST_DIRECTORY_IF_WANTED \;
fi
# Commit
git add .
git commit -m "<bot> update dependencies*.log files(s)" || true # okay if no change
shell: bash
- name: Push changes
if: env.IS_GIT_BEHIND != 'true'
run: |
# push changes (if needed)
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
status=`git status 2>&1 | tee`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
if [ "$ahead" -eq "1" ]; then
echo "no changes needed"
exit 0
fi
git push
echo "changes pushed"
shell: bash