From 468c03f14c28f032574166956d36a87af110fc43 Mon Sep 17 00:00:00 2001 From: James Fennell Date: Sun, 21 Apr 2024 22:26:54 -0400 Subject: [PATCH] Distribute pre-built binaries in releases (#136) --- .github/workflows/ci.yml | 22 ++++++++++++++++++---- .gitignore | 2 ++ .goreleaser.yaml | 28 ++++++++++++++++++++++++++++ README.md | 15 +++++++++++++++ docker-compose.yaml | 25 ------------------------- 5 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 .goreleaser.yaml delete mode 100644 docker-compose.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7f3eb7b..2d0926fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,14 @@ jobs: run: | BASE_VERSION=$(cat internal/version/BASE_VERSION) VERSION=${BASE_VERSION}-dev.build${{ github.run_number }} + PUSH_DOCKER='false' + IS_RELEASE='false' # If this is a push to mainline, give it the beta release if [ "${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }}" = "true" ] then VERSION=${BASE_VERSION}-beta.build${{ github.run_number }} + PUSH_DOCKER='true' fi # If this is a release, give it the full version. @@ -30,10 +33,14 @@ jobs: if [ "${{ github.ref }}" = "refs/tags/v${BASE_VERSION}" ] then VERSION=${BASE_VERSION} + PUSH_DOCKER='true' + IS_RELEASE='true' fi echo "Setting version to ${VERSION}" echo "TRANSITER_VERSION=${VERSION}" >> $GITHUB_ENV + echo "TRANSITER_PUSH_DOCKER=${PUSH_DOCKER}" >> $GITHUB_ENV + echo "TRANSITER_IS_RELEASE=${IS_RELEASE}" >> $GITHUB_ENV - name: Launch Postgres run: docker run -d --env POSTGRES_USER=transiter --env POSTGRES_PASSWORD=transiter --env POSTGRES_DB=transiter -p 5432:5432 postgis/postgis:14-3.4 @@ -54,16 +61,14 @@ jobs: - name: Login to DockerHub uses: docker/login-action@v2 - # Only push to Docker Hub if this workflow is a push to mainline - if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }} + if: ${{ env.TRANSITER_PUSH_DOCKER == 'true' }} with: username: jamespfennell password: ${{ secrets.DOCKER_HUB_PASSWORD }} - name: Push to Docker Hub uses: docker/build-push-action@v4 - # Only push to Docker Hub if this workflow is a push to mainline - if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }} + if: ${{ env.TRANSITER_PUSH_DOCKER == 'true' }} with: tags: | jamespfennell/transiter:latest @@ -72,3 +77,12 @@ jobs: "TRANSITER_VERSION=${{ env.TRANSITER_VERSION }}" context: . push: true + + - name: Run goreleaser + uses: goreleaser/goreleaser-action@v2 + if: ${{ env.TRANSITER_IS_RELEASE == 'true' }} + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index b0688d14..4f4837ca 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ __pycache__ env .pytest_cache transiter2 + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..36ece220 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,28 @@ +version: 1 + +builds: + - goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -X github.com/jamespfennell/transiter/internal/version.version={{ .Env.TRANSITER_VERSION }} + + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip diff --git a/README.md b/README.md index 9530fa8c..44c9ed01 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,21 @@ Then run the code generation: just generate ``` +### Creating a release + +Releases are created in the GitHub UI. +The release number `vX.Y.Z` must match the contents of the file `internal/version/BASE_VERSION`. +In the releases UI: + +- Use a new tag with name `vX.Y.Z`. +- Set the release name to `vX.Y.Z`. +- Mark the release as a pre-release. + The goreleaser infrastructure will automatically promote it to a full release + when the assets are pushed. + +After the release is created, bump the version number in `internal/version/BASE_VERSION` + and commit to mainline. + ## License MIT diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 66ce61d7..00000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,25 +0,0 @@ -version: '3.5' - -services: - - postgres: - image: postgis/postgis:14-3.4 - environment: - - POSTGRES_USER=transiter - - POSTGRES_PASSWORD=transiter - - POSTGRES_DB=transiter - ports: - - "5432:5432" - - transiter-server: - image: jamespfennell/transiter:latest - entrypoint: - - transiter - - server - - -p - - postgres://transiter:transiter@postgres:5432/transiter - ports: - - "8080:8080" - - "8081:8081" - - "8082:8082" - - "8083:8083"