Skip to content

Commit

Permalink
ci/stitchmd: Don't build from source, use action (uber-go#180)
Browse files Browse the repository at this point in the history
This replaces the manual compilation and running of stitchmd
with the [stitchmd-action](https://github.com/abhinav/stitchmd-action).
The action downloads a pre-built copy of stitchmd from GitHub,
and runs it.

The action offers multiple execution modes. Those relevant here are:

- check: fail if the file is not up-to-date
- write: update the file if it's not up-to-date

The workflow added here uses both:

- For a push to any branch, it will run in check mode. Read-only.
  It'll check that the file is up-to-date and that's it.
- However, if a pull request is created with a branch,
  it will run in write mode -- automatically updating the PR if needed.

This has some nice properties in terms of UX and safety:

- We never push to a branch without permission.
  This alleviates safety concerns around automated pushes.
- We make it easy to make edits on the GitHub UI,
  and still have them be picked up by the system
  without creating a local checkout
- Setting up Go, building stitchmd from source, and then running it--all
  this takes some time.
  It's *a lot* faster to download and run the binary.

The instructions taken to set up this dual mode
can be found here:
https://github.com/abhinav/stitchmd-action#automatically-update-for-prs-only

Note that this nukes the tools/ directory, but keeps the `Makefile`
so that if someone wants to run this locally, they still can.
  • Loading branch information
abhinav authored Apr 25, 2023
1 parent 42f94b6 commit 0bfd9f1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 72 deletions.
35 changes: 25 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,34 @@ on:
branches: [ '*' ]

jobs:

build:
stitchmd:
name: Check or update style.md
runs-on: ubuntu-latest

# Needed to give the job permission
# to push to branches.
permissions:
contents: write

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

- name: Set up Go
uses: actions/setup-go@v4
- name: Check or update style.md
uses: abhinav/stitchmd-action@v1
with:
go-version: 1.20.x
cache: true
cache-dependency-path: tools/go.sum
# For pull requests, run in 'write' mode so that edits made
# directly in the GitHub UI get propagated to style.md
# without a local checkout.
#
# Otherwise, run in 'check' mode to fail CI if style.md is out-of-date.
mode: ${{ github.event_name == 'pull_request' && 'write' || 'check' }}
summary: src/SUMMARY.md
preface: src/preface.txt
output: style.md

- name: Lint
run: make lint
- uses: stefanzweifel/git-auto-commit-action@v4
if: ${{ github.event_name == 'pull_request' }}
with:
file_pattern: style.md
commit_message: 'Auto-update style.md'
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ SHELL = /bin/bash
export GOBIN ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/bin

STITCHMD = $(GOBIN)/stitchmd

# Keep these options in-sync with .github/workflows/ci.yml.
STITCHMD_ARGS = -o style.md -preface src/preface.txt src/SUMMARY.md

.PHONY: all
Expand All @@ -21,5 +23,5 @@ lint: $(STITCHMD)
style.md: $(STITCHMD) $(wildcard src/*)
$(STITCHMD) $(STITCHMD_ARGS)

$(STITCHMD): tools/go.mod
go install -C tools go.abhg.dev/stitchmd
$(STITCHMD):
go install go.abhg.dev/stitchmd@latest
19 changes: 0 additions & 19 deletions tools/go.mod

This file was deleted.

33 changes: 0 additions & 33 deletions tools/go.sum

This file was deleted.

8 changes: 0 additions & 8 deletions tools/tools.go

This file was deleted.

0 comments on commit 0bfd9f1

Please sign in to comment.