When releasing the following procedure can be followed:

* First, release a release candidate (see
  notes/agda-stable-releases-candidates).

* Use the branch used for releasing the release candidate.

* Finish the release notes in
  doc/release-notes/<version-written-with-dashes>.md.

  Copy the contents of the release notes to the top of the CHANGELOG
  file.

* Run the `closed-issues` program for adding the closed issues to the
  CHANGELOG excluding issues labelled with:

  not-in-changelog,
  status: abandoned,
  status: duplicated,
  status: invalid,
  status: wontfix or
  status: working-as-intended

* Update the README.md, if necessary.

* Update the list of contributors if necessary.

  Note: This is duplicated in the following locations:

  - Agda.cabal
  - doc/user-manual/conf.py
  - doc/user-manual/team.rst
  - LICENSE

* Update the LICENSE file, if necessary.

* Update Stackage resolvers, if necessary.

* Verify that the Travis builds have no errors.

* Update in the bug tracker the milestone field of open issues to the
  next Agda version.

* Get a clean Agda repository.

    MAJORVERSION=<current-development-version-eg-2.4.2>
    VERSION=<current-released-version-eg-2.4.0.2>
    git clone git@github.com:agda/agda.git agda-release
    cd agda-release
    git checkout master

* The $CHANGE_VERSION_FILES variable represents the files where it is
  necessary to change the version number.

    $CHANGE_VERSION_FILES=
      .ghci
      Agda.cabal
      default.nix
      doc/user-manual/conf.py
      mk/versions.mk
      src/data/emacs-mode/agda2-mode.el
      src/data/emacs-mode/agda2-mode-pkg.el
      src/size-solver/size-solver.cabal
      test/interaction/Issue1244a.out
      test/interaction/Issue1244b.out

* Change version to $MAJORVERSION in $CHANGE_VERSION_FILES.

* Obtain and install the standard library branch related to the Agda:

    make up-to-date-std-lib

* Run the test-suite:

    make install
    make test

  Note that "make install" invokes "agda-mode compile", which should
  ensure that the Emacs mode can be compiled without errors or
  warnings (except for the "cl package required at runtime" warning).

* Remove -Werror and -fprof-auto from Agda.cabal (this is required by
  `cabal --check`).

* Remove the Cabal test-suite from Agda.cabal.

* Update the user manual:

    make user-manual-pdf

* Build source distributions:

    cabal configure
    cabal check
    cabal sdist

* Build documentation for uploading to Hackage. Adapted from
  https://hackage.haskell.org/upload (2018-07-19):

    cabal haddock --for-hackage

* Ensure that the package builds properly (with multiple versions of
  GHC if possible) in Linux, macOS and Windows.

    BASE=`pwd`
    cd ${TMPDIR:-/tmp}
    tar xzf $BASE/dist/Agda-$MAJORVERSION.tar.gz
    cd Agda-$MAJORVERSION
    cabal install

  Do not forget to test the Emacs mode.

* Tag the relase (do not forget to record the changes above first):

    cd $BASE
    git tag -a v$MAJORVERSION -m "Agda $MAJORVERSION stable release"

* Upload the tarball and the documentation to Hackage (tested with
  cabal-install >= 2.0.0.0):

    cd $BASE
    cabal upload --publish dist/Agda-$MAJORVERSION.tar.gz
    cabal upload --publish -d dist/Agda-$MAJORVERSION-docs.tar.gz

* Restore the Cabal test-suite in Agda.cabal.

* Restore -Werror and -fprof-auto in Agda.cabal.

* Push all changes (in the release-$MAJORVERSION branch):

    git push --follow-tags

* Add a new header to CHANGELOG.

* Add a new entry in
  doc/release-notes/<version-written-with-dashes>.md.

* Close in the bug tracker the milestone $MAJORVERSION.

* Update Agda Manual on Readthedocs.org (see Issues #2844 and #3035)

  ** You need Admin permissions on the Agda readthedocs.org project
     (current admins: asr, andreasabel, phile314)

  ** Go to readthedocs.org -> Agda Project -> Admin -> Versions

  ** Mark $MAJORVERSION as active

  ** Set the default documentation version to $MAJORVERSION

  ** If a release candidate was released then remove the associated
     documentation.

* Update the Agda Wiki:

  ** Update the Download page:

     *** Move the current version information to the old releases
         section.

     *** Update the last release information.

  ** Update the Main page.

  ** Is the current version of the standard library compatible with
     the new version of Agda? If so, to update the standard library
     page.

* If we are releasing a bux-fix release then deprecate in Hackage the
  buggy version.

* Announce the release of the new version on the Agda mailing lists
  (users and developers).

* Enable the released version of Agda on Stackage, if necessary.
