-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
187 lines (162 loc) · 7.1 KB
/
update-flathub-repo.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
---
# This action is a candidate to centrally manage in https://github.com/<organization>/.github/
# If more Flathub applications are developed, consider moving this action to the organization's .github repository,
# using the `flathub-pkg` repository label to identify repositories that should trigger this workflow.
# Update Flathub on release events.
name: Update flathub repo
on:
release:
types: [released]
concurrency:
group: "${{ github.workflow }}-${{ github.event.release.tag_name }}"
cancel-in-progress: true
jobs:
update-flathub-repo:
env:
FLATHUB_PKG: dev.lizardbyte.app.${{ github.event.repository.name }}
if: >-
github.repository_owner == 'LizardByte'
runs-on: ubuntu-latest
steps:
- name: Check if flathub repo
env:
TOPIC: flathub-pkg
id: check-label
uses: actions/github-script@v7
with:
script: |
const topic = process.env.TOPIC;
console.log(`Checking if repo has topic: ${topic}`);
const repoTopics = await github.rest.repos.getAllTopics({
owner: context.repo.owner,
repo: context.repo.repo
});
console.log(`Repo topics: ${repoTopics.data.names}`);
const hasTopic = repoTopics.data.names.includes(topic);
console.log(`Has topic: ${hasTopic}`);
core.setOutput('hasTopic', hasTopic);
- name: Check if latest GitHub release
id: check-release
if: >-
steps.check-label.outputs.hasTopic == 'true'
uses: actions/github-script@v7
with:
script: |
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
});
core.setOutput('isLatestRelease', latestRelease.data.tag_name === context.payload.release.tag_name);
- name: Checkout
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
uses: actions/checkout@v4
- name: Checkout flathub-repo
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
uses: actions/checkout@v4
with:
repository: "flathub/${{ env.FLATHUB_PKG }}"
path: "flathub/${{ env.FLATHUB_PKG }}"
- name: Clean up legacy files
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
working-directory: flathub/${{ env.FLATHUB_PKG }}
run: |
rm -rf ./*
- name: Copy github files
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
working-directory: flathub/${{ env.FLATHUB_PKG }}
run: |
mkdir -p .github/ISSUE_TEMPLATE
# sponsors
curl -sSL https://github.com/LizardByte/.github/raw/refs/heads/master/.github/FUNDING.yml \
-o .github/FUNDING.yml
# pull request template
curl -sSL https://github.com/LizardByte/.github/raw/refs/heads/master/.github/pull_request_template.md \
-o .github/pull_request_template.md
# issue config
curl -sSL https://github.com/LizardByte/.github/raw/refs/heads/master/.github/ISSUE_TEMPLATE/config.yml \
-o .github/ISSUE_TEMPLATE/config.yml
- name: Download release asset
id: download
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
uses: robinraju/[email protected]
with:
repository: "${{ github.repository }}"
tag: "${{ github.event.release.tag_name }}"
fileName: "flathub.tar.gz"
tarBall: false
zipBall: false
out-file-path: "flathub/${{ env.FLATHUB_PKG }}"
extract: true
- name: Delete arhive
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
run: |
rm -f flathub/${{ env.FLATHUB_PKG }}/flathub.tar.gz
- name: Update metainfo.xml
id: update_metainfo
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
run: |
xml_file="flathub/${{ env.FLATHUB_PKG }}/${{ env.FLATHUB_PKG }}.metainfo.xml"
# Extract release information
version="${{ github.event.release.tag_name }}" && version="${version#v}"
date="${{ github.event.release.published_at }}" && date="${date%%T*}"
changelog="${{ github.event.release.body }}" && changelog="${changelog//&/&}" && \
changelog="${changelog//</<}" && changelog="${changelog//>/>}"
# Store the old release information into a temp file to be used for precise replacement
tmpfile=$(mktemp)
# Match the existing <release> block, replace it with the new data
awk -v version="$version" -v date="$date" -v changelog="$changelog" '
BEGIN { replaced = 0 }
/<release version=.*>/ {
if (!replaced) {
print "<release version=\"" version "\" date=\"" date "\">"
print "<description><p>" changelog "</p></description>"
print "</release>"
replaced = 1
}
}
!/<release version=.*>/ && !/<\/release>/ { print $0 }
' "$xml_file" > "$tmpfile"
# Move the updated file back to the original location
mv "$tmpfile" "$xml_file"
- name: Update submodule
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true'
run: |
# Get the current commit of the submodule in the main repository
git submodule update --init packaging/linux/flatpak/deps/shared-modules
cd ${{ github.workspace }}/packaging/linux/flatpak/deps/shared-modules
main_commit=$(git rev-parse HEAD)
# update submodules
cd ${{ github.workspace }}/flathub/${{ env.FLATHUB_PKG }}
git submodule update --init shared-modules
cd shared-modules
git checkout $main_commit
- name: Create/Update Pull Request
if: >-
steps.check-label.outputs.hasTopic == 'true' &&
steps.check-release.outputs.isLatestRelease == 'true' &&
fromJson(steps.download.outputs.downloaded_files)[0]
uses: peter-evans/create-pull-request@v7
with:
path: "flathub/${{ env.FLATHUB_PKG }}"
token: ${{ secrets.GH_BOT_TOKEN }}
commit-message: "chore: Update ${{ env.FLATHUB_PKG }} to ${{ github.event.release.tag_name }}"
branch: bot/bump-${{ env.FLATHUB_PKG }}-${{ github.event.release.tag_name }}
delete-branch: true
title: "chore: Update ${{ env.FLATHUB_PKG }} to ${{ github.event.release.tag_name }}"
body: ${{ github.event.release.body }}