« Back to Index

Go: GitHub Actions update app dependencies daily with private repo access

View original Gist on GitHub

Tags: #ci #cron #go

dependencies.yaml

name: Update Dependencies and Run Tests

on:
  # Schedule to run at 9am UTC every day
  schedule:
    - cron: '0 9 * * *'

  # Allow manual trigger via GitHub UI
  workflow_dispatch:

jobs:
  update-deps-and-test:
    runs-on: ubuntu-latest

    steps:
    - name: Check out repository
      uses: actions/checkout@v3

    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version-file: 'go.mod'

    - name: Set up private Go modules
      run: |
        echo "Setting up GOPRIVATE and GitHub token"
        echo "machine github.com login ${{ secrets.GH_PAT_CI }}" > ~/.netrc
      env:
        GOPRIVATE: "github.com/some_private_repo" # <<<<<<<<<<<<<<<<<< UPDATE THIS

    - name: Update dependencies
      run: |
        go get -u -t ./...
        go mod tidy

    - name: Run tests
      env:
        GO_TESTARGS: "-count=1 -v -run=Test ./..."
      run: go test -race  -count=1 -v -run=Test ./...

    - name: Commit changes
      if: success()
      run: |
        git config --global user.name "github-actions[bot]"
        git config --global user.email "github-actions[bot]@users.noreply.github.com"
        git add .
        git commit -m "build: update dependencies [skip ci]"
        git push