forked from stevesbrain/bitlbee-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
111 lines (95 loc) · 4.12 KB
/
update-dependancies.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
name: Update Bitlbee Dependencies
on:
schedule:
- cron: '0 0 * * *' # Daily at 00:00 UTC
workflow_dispatch:
push:
branches:
- master
jobs:
check-and-update:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check dependencies for updates
id: check_deps
uses: actions/github-script@v7
with:
script: |
const deps = {
'BITLBEE': { owner: 'bitlbee', repo: 'bitlbee' },
'DISCORD': { owner: 'sm00th', repo: 'bitlbee-discord' },
'INSTAGRAM': { owner: 'EionRobb', repo: 'purple-instagram' },
'FACEBOOK': { owner: 'jgeboski', repo: 'bitlbee-facebook' },
'SKYPE': { owner: 'EionRobb', repo: 'skype4pidgin' },
'SLACK': { owner: 'dylex', repo: 'slack-libpurple' },
'STEAM': { owner: 'bitlbee', repo: 'bitlbee-steam' },
'TELEGRAM': { owner: 'majn', repo: 'telegram-purple' }
};
const fs = require('fs');
const dockerfile = fs.readFileSync('Dockerfile', 'utf8');
let updates = {};
let hasUpdates = false;
for (const [key, repo] of Object.entries(deps)) {
const result = await github.rest.repos.getBranch({
owner: repo.owner,
repo: repo.repo,
branch: 'master'
});
const latestCommit = result.data.commit.sha.substring(0, 7);
const currentCommit = dockerfile.match(new RegExp(`ENV ${key}_COMMIT ([a-f0-9]+)`))[1];
if (currentCommit !== latestCommit) {
updates[key] = {
current: currentCommit,
latest: latestCommit,
owner: repo.owner,
repo: repo.repo
};
hasUpdates = true;
}
}
core.setOutput('has_updates', hasUpdates);
core.setOutput('updates', JSON.stringify(updates));
- name: Update Dockerfile and README
if: steps.check_deps.outputs.has_updates == 'true'
run: |
UPDATES='${{ steps.check_deps.outputs.updates }}'
# Update Dockerfile
for key in $(echo $UPDATES | jq -r 'keys[]'); do
current=$(echo $UPDATES | jq -r ".[\"$key\"].current")
latest=$(echo $UPDATES | jq -r ".[\"$key\"].latest")
sed -i "s/ENV ${key}_COMMIT ${current}/ENV ${key}_COMMIT ${latest}/" Dockerfile
# Update README
owner=$(echo $UPDATES | jq -r ".[\"$key\"].owner")
repo=$(echo $UPDATES | jq -r ".[\"$key\"].repo")
full_sha=$(echo $UPDATES | jq -r ".[\"$key\"].latest")
sed -i "s|\[$current\](https://github.com/$owner/$repo/commit/[a-f0-9]\+)|\[$latest\](https://github.com/$owner/$repo/commit/$full_sha)|" README.md
done
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
if: steps.check_deps.outputs.has_updates == 'true'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: realies/bitlbee:latest
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
cache-from: type=registry,ref=realies/bitlbee:cache
cache-to: type=inline,mode=max,ref=realies/bitlbee:cache
- name: Commit changes if needed
if: steps.check_deps.outputs.has_updates == 'true'
run: |
git config user.email "${{ secrets.USER_EMAIL }}"
git config user.name "${{ secrets.USER_NAME }}"
git add Dockerfile README.md
git commit -m "update dependencies to latest commits"
git push