Skip to content

Commit

Permalink
Distribute pre-built binaries in releases (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespfennell committed Apr 22, 2024
1 parent cc4308a commit 468c03f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ 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.
# A release is defined as a tag push where the tag is `v<base version>`.
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
Expand All @@ -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
Expand All @@ -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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ __pycache__
env
.pytest_cache
transiter2

dist/
28 changes: 28 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 0 additions & 25 deletions docker-compose.yaml

This file was deleted.

0 comments on commit 468c03f

Please sign in to comment.