Skip to content

Update Vencord

Update Vencord #754

name: Update Vencord
on:
schedule:
- cron: "0 */8 * * *" # Every 8 hours
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
update-vencord:
name: Update Vencord ${{ matrix.variant }}
runs-on: ubuntu-latest
timeout-minutes: 4
permissions:
contents: write
actions: write
strategy:
matrix:
include:
- variant: "Stable"
unstable: false
version_expr: "version"
commit_prefix: "vencord"
- variant: "Unstable"
unstable: true
version_expr: "src.rev"
commit_prefix: "vencord-unstable"
version_truncate: true
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 1
- uses: DeterminateSystems/nix-installer-action@v16
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get old version
id: old-version
shell: bash
run: |
VERSION_EXPR="${{ matrix.version_expr }}"
OLD_VERSION=$(nix eval --impure --raw --expr \
"with import <nixpkgs> {}; (callPackage ./pkgs/vencord.nix { unstable = ${{ matrix.unstable }}; }).$VERSION_EXPR")
${{ matrix.version_truncate && 'OLD_VERSION=${OLD_VERSION:0:7}' || '' }}
echo "version=$OLD_VERSION" >> $GITHUB_OUTPUT
- name: Update Vencord ${{ matrix.variant }}
id: update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! nix build --impure --expr 'let pkgs = import <nixpkgs> {}; in (pkgs.callPackage ./pkgs/vencord.nix { unstable = ${{ matrix.unstable }}; }).passthru.updateScript'; then
echo "Failed to build the update script."
exit 1
fi
if ! ./result/bin/vencord-update; then
echo "Update script failed to execute successfully"
exit 1
fi
echo "Vencord ${{ matrix.variant }} update finished."
rm ./result
- name: Get new version
id: new-version
shell: bash
run: |
VERSION_EXPR="${{ matrix.version_expr }}"
NEW_VERSION=$(nix eval --impure --raw --expr \
"with import <nixpkgs> {}; (callPackage ./pkgs/vencord.nix { unstable = ${{ matrix.unstable }}; }).$VERSION_EXPR")
${{ matrix.version_truncate && 'NEW_VERSION=${NEW_VERSION:0:7}' || '' }}
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Test Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! nix-build -E 'with import <nixpkgs> {}; callPackage ./pkgs/vencord.nix { unstable = ${{ matrix.unstable }}; }'; then
echo "Build failed"
exit 1
fi
unlink result
- name: Commit changes
id: commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: success() && steps.old-version.outputs.version != steps.new-version.outputs.version
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
if [[ -n "$(git status --porcelain pkgs/vencord.nix)" ]]; then
git add pkgs/vencord.nix
git commit -m "github: update ${{ matrix.commit_prefix }} ${{ steps.old-version.outputs.version }} -> ${{ steps.new-version.outputs.version }}"
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit"
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: success() && steps.commit.outputs.changes == 'true'
run: |
for i in {1..3}; do
git fetch origin
git pull --rebase origin ${{ github.ref_name }}
if git push; then
echo "Successfully pushed changes"
break
fi
echo "Push failed, retrying in 5 seconds..."
sleep 5
done