This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (111 loc) · 5.27 KB
/
update-utils.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
120
121
122
123
124
125
126
127
128
129
130
131
name: Deploying utils package
on:
schedule:
- cron: "0 0 * * *" # run at the start of every day after script repos update
workflow_dispatch:
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
env:
public_key: ${{ secrets.PUBLIC }}
private_key: ${{ secrets.PRIVATE }}
jobs:
check-sha:
runs-on: ubuntu-latest
outputs:
match_results: ${{ steps.check-shas.outputs.match_results }}
postinstall_remote_sha: ${{ steps.check-shas.outputs.postinstall_remote_sha }}
audio_remote_sha: ${{ steps.check-shas.outputs.audio_remote_sha }}
steps:
- name: Checking out repository code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Download remote commit shas
id: check-shas
run: |
# Download remote shas
postinstall_latest_sha=$(curl -s https://api.github.com/repos/eupnea-project/eupnea-utils/commits/main | jq -r '.sha')
# fail if curl result is empty
if [[ "$postinstall_latest_sha" = "null" ]]; then
echo "latest_tag is empty"
exit 1
fi
audio_latest_sha=$(curl -s https://api.github.com/repos/eupnea-project/audio-scripts/commits/main | jq -r '.sha')
# fail if curl result is empty
if [[ "$audio_latest_sha" = "null" ]]; then
echo "latest_tag is empty"
exit 1
fi
# Check remote shas against cached ones
postinstall_match_results=$([[ "$(cat cache/utils_sha-cache.txt | head -1)" == "$postinstall_latest_sha" ]] && echo "true" || echo "false")
audio_match_results=$([[ "$(cat cache/utils_sha-cache.txt | tail -1)" == "$audio_latest_sha" ]] && echo "true" || echo "false")
# Compare results and determine if there was an update in any of the repos
if [[ "$postinstall_match_results" == "true" && "$audio_match_results" == "true" ]]; then
echo "match_results=true" >> $GITHUB_OUTPUT
else
echo "match_results=false" >> $GITHUB_OUTPUT
fi
# Add shas to output
echo "postinstall_remote_sha=$postinstall_latest_sha" >> $GITHUB_OUTPUT
echo "audio_remote_sha=$audio_latest_sha" >> $GITHUB_OUTPUT
deploy-repo:
runs-on: ubuntu-latest
needs: check-sha # needs for the vars from the previous job
# Only run script when remote sha has changed, aka the results DON'T match
if: needs.check-sha.outputs.match_results == 'false'
steps:
- name: Checking out repository code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Installing dependencies
run: sudo apt-get install -y rpm createrepo-c
- name: Update local commits sha file
run: |
echo "${{ needs.check-sha.outputs.postinstall_remote_sha }}"$'\n'"${{ needs.check-sha.outputs.audio_remote_sha }}" > cache/utils_sha-cache.txt
- name: Bump version in spec file
run: |
CURRENT_VERSION=$(sed -n '2p' spec-files/eupnea-utils.spec | sed 's/.*://' | xargs) # get current version from spec file
NEXTVERSION=$(echo ${CURRENT_VERSION} | awk -F. -v OFS=. '{$NF += 1 ; print}') # bump version
sed -i "2s/.*/Version: ${NEXTVERSION}/" spec-files/eupnea-utils.spec # update version in spec file
- name: Packing rpm package
run: rpmbuild -bb spec-files/eupnea-utils.spec
- name: Downloading old repo
run: |
# Download old repo.
# Exit in case the branch doesn't exist yet
git clone --branch=gh-pages https://github.com/eupnea-project/rpm-repo /tmp/rpm-repo || exit 0
# Copy system rpms to current directory
cp -r /tmp/rpm-repo/*.rpm .
# Delete old util packages
rm -rf ./eupnea-utils*.rpm
- name: Creating repo
run: bash create-repo.sh
- name: Updating files in main branch
uses: stefanzweifel/git-auto-commit-action@v4
with:
# Disable setting repo owner as commit author
commit_user_name: github-actions[bot]
commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com
commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
commit_message: Update files in main branch
# Only include needed files
file_pattern: 'spec-files/eupnea-utils.spec cache/utils_sha-cache.txt'
- name: Deploying utils packages
uses: stefanzweifel/git-auto-commit-action@v4
with:
# Disable setting repo owner as commit author
commit_user_name: github-actions[bot]
commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com
commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
commit_message: Deploy util packages
branch: gh-pages
create_branch: true
# Only include needed files
file_pattern: 'repodata/* *.rpm eupnea.repo public_key.gpg'
push_options: '--force'