-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (82 loc) · 2.61 KB
/
python-app.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
name: pun-fasce test run
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '0 5 3 * *'
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# Run application
- name: Run application
id: run_script
run: |
ANNO=$(( $(date +'%m') < 2 ? $(date +'%Y') - 1 : $(date +'%Y') ))
echo "Running app in $(date +'%m/%Y') for year $ANNO."
{
echo "result<<EOF"
python pun-fasce.py $ANNO
echo EOF
} >> $GITHUB_ENV
# Show output (using environment variable to avoid quoting)
- name: Show application output
run: echo -e "$RES"
shell: bash
env:
RES: ${{ env.result }}
# Environment variable character escaping
- name: Character escaping
id: run_escaping
run: |
RES="${RES//$'\n'/\\n}" # Escape new lines
RES="${RES//$'\t'/\\t}" # Escape tabs
RES=${RES//\//\\\/} # Escape slashes
echo "Escaped RES (env.result) = |$RES|"
echo "result=$RES" >> $GITHUB_ENV
shell: bash
env:
RES: ${{ env.result }}
# Update README with content of environment variable
- name: Update README.md
run: |
# Replace anything after line with "Il risultato"
sed -i -n -e '/Il risultato/{p;a\' -e '\n```text\n${{ env.result }}\n```' -e '}' -e '/Il risultato/,$!p' README.md
# Push changes to repository, if any
- name: Check for changes
id: check_changes
run: |
git diff --exit-code > /dev/null && echo 'changed=false' >> $GITHUB_ENV || echo 'changed=true' >> $GITHUB_ENV
- name: Pull-request
uses: repo-sync/pull-request@v2
if: env.changed == 'true'
with:
destination_branch: "main"
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Commit
if: env.changed == 'true'
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add .
git commit -m "Aggiornamento dati mensili README" -a
- name: Push changes
if: env.changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}