Update Vencord #775
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Vencord | |
| on: | |
| schedule: | |
| - cron: "0 */8 * * *" # Every 8 hours | |
| workflow_dispatch: | |
| jobs: | |
| update-vencord: | |
| name: Update Vencord ${{ matrix.variant }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 4 | |
| permissions: | |
| contents: write | |
| actions: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ matrix.variant }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| strategy: | |
| fail-fast: false | |
| 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 | |
| - 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 | |
| echo "Old ${{ matrix.variant }} version: $OLD_VERSION" | |
| - 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 | |
| echo "New ${{ matrix.variant }} version: $NEW_VERSION" | |
| if [[ "${{ steps.old-version.outputs.version }}" == "$NEW_VERSION" ]]; then | |
| echo "No version change detected for ${{ matrix.variant }} - no commit needed" | |
| else | |
| echo "Version changed for ${{ matrix.variant }}: ${{ steps.old-version.outputs.version }} -> $NEW_VERSION" | |
| fi | |
| - 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() | |
| run: | | |
| echo "Checking for changes for ${{ matrix.variant }}: ${{ steps.old-version.outputs.version }} -> ${{ steps.new-version.outputs.version }}" | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git config --global pull.rebase true | |
| git config --global rebase.autoStash true | |
| 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 | |
| echo "Successfully committed changes for ${{ matrix.variant }}" | |
| else | |
| echo "No file changes detected for ${{ matrix.variant }} - skipping 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..10}; do | |
| echo "Attempt $i: Fetching latest changes..." | |
| git fetch origin | |
| echo "Rebasing local changes..." | |
| if ! git pull --rebase origin ${{ github.ref_name }}; then | |
| echo "Rebase failed on attempt $i, retrying..." | |
| sleep $((i * 2)) | |
| continue | |
| fi | |
| echo "Pushing changes..." | |
| if git push origin HEAD:${{ github.ref_name }}; then | |
| echo "Successfully pushed changes on attempt $i" | |
| break | |
| fi | |
| echo "Push failed on attempt $i, retrying in $((i * 2)) seconds..." | |
| sleep $((i * 2)) | |
| if [ $i -eq 10 ]; then | |
| echo "Failed to push after 10 attempts" | |
| git log --oneline -5 | |
| git status | |
| exit 1 | |
| fi | |
| done |