187 lines
6.8 KiB
YAML
187 lines
6.8 KiB
YAML
---
|
|
# This workflow is centrally managed in https://github.com/<organization>/.github/
|
|
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
|
|
# the above-mentioned repo.
|
|
|
|
# To use, add the `flathub-pkg` repository label to identify repositories that should trigger this workflow.
|
|
|
|
# Update Flathub on release events.
|
|
|
|
name: Update flathub repo
|
|
permissions:
|
|
contents: read
|
|
|
|
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
|
|
id: check-label
|
|
env:
|
|
TOPIC: flathub-pkg
|
|
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/release-downloader@v1.12
|
|
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 archive
|
|
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
|
|
changelog="${{ github.event.release.body }}" && changelog="${changelog//&/&}" && \
|
|
changelog="${changelog//</<}" && changelog="${changelog//>/>}"
|
|
|
|
# Replace changelog placeholder with actual changelog
|
|
sed -i "s|<!-- changelog -->|$changelog|g" "$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
|
|
id: create-pr
|
|
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 }}
|
|
|
|
- name: Automerge PR
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
|
|
if: >-
|
|
steps.check-label.outputs.hasTopic == 'true' &&
|
|
steps.check-release.outputs.isLatestRelease == 'true' &&
|
|
fromJson(steps.download.outputs.downloaded_files)[0]
|
|
run: |
|
|
gh pr merge \
|
|
--auto \
|
|
--delete-branch \
|
|
--repo "flathub/${{ env.FLATHUB_PKG }}" \
|
|
--squash \
|
|
"${{ steps.create-pr.outputs.pull-request-number }}"
|