Skip to content

Instantly share code, notes, and snippets.

@farcaller
Created February 25, 2024 17:59
Show Gist options
  • Save farcaller/00ff45b678ebe4cb260a0f9cd1676b22 to your computer and use it in GitHub Desktop.
Save farcaller/00ff45b678ebe4cb260a0f9cd1676b22 to your computer and use it in GitHub Desktop.
name: Dependabot auto-merge
on: pull_request
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
workflows: ${{ steps.filter.outputs.workflows }}
gomod: ${{ steps.filter.outputs.gomod }}
steps:
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
workflows:
- '.github/workflows/**'
gomod:
- 'go.mod'
- 'go.sum'
- 'gomod2nix.toml'
dependabot-gomod:
needs: changes
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
if: ${{ needs.changes.outputs.gomod == 'true' && github.actor == 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v4
- name: Checkout PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr checkout ${{ github.event.pull_request.number }}
- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: fregante/setup-git-user@v2
- env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
nix run github:nix-community/gomod2nix generate
if [[ $(git diff --stat) != '' ]]; then
git add gomod2nix.toml
git commit -m "Update gomod2nix.toml"
git push
fi
- id: build
run: |
nix build .#mailpusher -o result
name: update-nix-deps
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch: {}
permissions:
contents: write
jobs:
update-nix-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: fregante/setup-git-user@v2
- name: Install Nix
uses: cachix/install-nix-action@v20
with:
extra_nix_config: 'experimental-features = nix-command flakes'
nix_path: nixpkgs=channel:nixos-unstable
- name: Update lockfiles
run: |
set -euxo pipefail
for FLAKEFILE in `find . -name flake.nix`; do
FLAKEDIR=$(dirname $FLAKEFILE)
pushd "$FLAKEDIR"
nix flake update
popd
done
if [[ -n $(git status -s) ]]; then
git add .
git commit -am 'Update the nix lockfiles'
git push
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment