  Chiral and non-chiral $p$-form gauge fields have gravitational anomalies and
anomalies of Green-Schwarz type. This means that they are most naturally
realized as the boundary modes of bulk topological phases in one higher
dimensions. We give a systematic description of the total bulk-boundary system
which is analogous to the realization of a chiral fermion on the boundary of a
massive fermion. The anomaly of the boundary theory is given by the partition
function of the bulk theory, which we explicitly compute in terms of the
Atiyah-Patodi-Singer $\eta$-invariant. We use our formalism to determine the
$\mathrm{SL}(2,{\mathbb Z})$ anomaly of the 4d Maxwell theory. We also apply it
to study the worldvolume theories of a single D-brane and an M5-brane in the
presence of orientifolds, orbifolds, and S-folds in string, M, and F theories.
In an appendix we also describe a simple class of non-unitary invertible
topological theories whose partition function is not a bordism invariant,
illustrating the necessity of the unitarity condition in the cobordism
classification of the invertible phases.
