Update Emacs #14
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 Emacs | |
| # Cron translator: <https://cron-checker.com/>. | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 0 * * 1" # At 12:00 AM, only on Monday. | |
| jobs: | |
| update-emacs: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
| - name: Get Current Commit | |
| run: echo "current_commit=$(grep "(define emacs-master-commit" emacs-master.scm | awk '{print $3}' | cut -c 2-41)" >> $GITHUB_ENV | |
| - name: Cache Emacs | |
| id: cache-emacs | |
| uses: actions/cache@640a1c2554105b57832a23eea0b4672fc7a790d5 | |
| with: | |
| path: emacs | |
| key: ${{ runner.os }}-emacs | |
| - name: Clone Emacs | |
| if: ${{ steps.cache-emacs.outputs.cache-hit != 'true' }} | |
| run: git clone https://github.com/emacs-mirror/emacs.git | |
| - name: Update Emacs | |
| if: ${{ steps.cache-emacs.outputs.cache-hit == 'true' }} | |
| run: cd emacs && git pull | |
| - name: Get Source Commit | |
| run: echo "source_commit=$(cd emacs && git rev-parse --verify HEAD)" >> $GITHUB_ENV | |
| - name: Compare Commits | |
| id: compare-commits | |
| run: | | |
| if [ "${{env.source_commit }}" != "${{ env.current_commit }}" ]; then | |
| echo "The commits are different. Continue the workflow." | |
| echo "different_commit='true'" >> $GITHUB_OUTPUT | |
| else | |
| echo "The commits are the same. Exiting the workflow..." | |
| echo "different_commit='false'" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Install Guix | |
| if: ${{ contains(steps.compare-commits.Outputs.different_commit, 'true') }} | |
| run: | | |
| sudo apt update -y | |
| sudo apt install guix -y | |
| - name: Get Hash | |
| if: ${{ contains(steps.compare-commits.Outputs.different_commit, 'true') }} | |
| run: echo "hash="$(guix hash -x --serializer=nar emacs)"" >> $GITHUB_ENV | |
| - name: Set Values | |
| if: ${{ contains(steps.compare-commits.Outputs.different_commit, 'true') }} | |
| run: | | |
| sed -i "s/define emacs-master-commit \"\(.*\)\"/define emacs-master-commit \"${{ env.source_commit }}\"/" emacs-master.scm | |
| sed -i "s/define emacs-master-hash \"\(.*\)\"/define emacs-master-hash \"${{ env.hash }}\"/" emacs-master.scm | |
| - name: Import GPG Key | |
| if: ${{ contains(steps.compare-commits.Outputs.different_commit, 'true') }} | |
| run: echo "$GPG_KEY" | base64 --decode | gpg --batch --import | |
| env: | |
| GPG_KEY: ${{ secrets.GPG_KEY }} | |
| - name: Custom GPG Signing Program | |
| if: ${{ contains(steps.compare-commits.Outputs.different_commit, 'true') }} | |
| run: | | |
| echo "#!/bin/bash" >> /tmp/gpg.sh | |
| echo "gpg --batch --pinentry-mode=loopback --passphrase \$GPG_KEY_PASSPHRASE \"\$@\"" >> /tmp/gpg.sh | |
| chmod +x /tmp/gpg.sh | |
| env: | |
| GPG_KEY_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} | |
| - name: Set up Git | |
| if: ${{ contains(steps.compare-commits.Outputs.different_commit, 'true') }} | |
| run: | | |
| git config commit.gpgsign true | |
| git config user.signingkey $GPG_KEY_ID | |
| git config gpg.program /tmp/gpg.sh | |
| env: | |
| GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} | |
| - name: Commit | |
| if: ${{ contains(steps.compare-commits.Outputs.different_commit, 'true') }} | |
| run: | | |
| git add emacs-master.scm | |
| short_commit=$(grep "(define emacs-master-commit" emacs-master.scm | awk '{print $3}' | cut -c 2-8) | |
| git commit -m "feat(emacs-master.scm): update emacs to $short_commit" --gpg-sign=$GPG_KEY_ID | |
| git push --set-upstream origin main | |
| env: | |
| GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} | |
| GPG_KEY_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} | |
| GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }} | |
| GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }} | |
| GIT_AUTHOR_NAME: github-actions | |
| GIT_AUTHOR_EMAIL: github-actions@example.com |