Skip to content

Commit

Permalink
Merge pull request #1 from phoops/feature/github_action
Browse files Browse the repository at this point in the history
Feature/GitHub action
  • Loading branch information
Carmine Di Monaco committed Nov 30, 2021
2 parents 0aa9b28 + bc09e5c commit ac38778
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 5 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/github-actions-on-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Golang test flow
on: [push]
jobs:
transitland-route-geometry-generator-test:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v2
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- name: Docker Compose Test Environment
uses: isbang/[email protected]
with:
down-flags: '--volumes'
compose-file: './docker-compose.yaml'
- name: Golang setup
uses: actions/setup-go@v2
with:
go-version: '^1.16.4'
- name: Go test
run: go test -v ./...
53 changes: 53 additions & 0 deletions .github/workflows/github-actions-on-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Github release flow
on:
release:
types:
- created
jobs:
release-build-attach:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v2
- name: Install Task
uses: arduino/setup-task@v1
- name: Build linux binary
run: task build-transitland-route-geometry-generator-prod
- name: Store Linux binary
uses: actions/upload-artifact@v1
with:
name: transitland-route-geometry-generator-linux
path: ${{ github.workspace }}/build/transitland-route-geometry-generator
- name: Download Linux binary
uses: actions/download-artifact@v1
with:
name: transitland-route-geometry-generator-linux
- name: Attach Linux binary to GitHub release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ github.workspace }}/transitland-route-geometry-generator-linux/transitland-route-geometry-generator
asset_name: transitland-route-geometry-generator-linux
asset_label: Linux binary
asset_content_type: application/binary



release-notes:
needs: release-build-attach
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm install github-release-notes -g
- run: gren release --override
env:
GREN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/github-actions-on-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: Docker release flow
on:
push:
tags:
- v*
jobs:
transitland-route-geometry-generator-test:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v2
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- name: Docker Compose Test Environment
uses: isbang/[email protected]
with:
down-flags: '--volumes'
compose-file: './docker-compose.yaml'
- name: Golang setup
uses: actions/setup-go@v2
with:
go-version: '^1.16.4'
- name: Go test
run: go test -v ./...
transitland-route-geometry-generator-release:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Install Task
uses: arduino/setup-task@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build docker image
run: task build-and-push-docker-images
env:
RELEASE_TAG: ${{ github.ref_name }}
115 changes: 113 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,120 @@

[![Go Report Card](https://goreportcard.com/badge/github.com/phoops/transitland-route-geometry-generator)](https://goreportcard.com/report/github.com/phoops/transitland-route-geometry-generator)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
[![Dockerhub Badge](https://img.shields.io/docker/pulls/phoops/transitland-route-geometry-generator.svg)]("https://img.shields.io/docker/pulls/phoops/transitland-route-geometry-generator.svg")

## Generate your transitland route shapes from gtfs trips - WIP
![Main branch](https://github.com/phoops/transitland-route-geometry-generator/actions/workflows/github-actions-on-push.yaml/badge.svg)
![Main branch docker](https://github.com/phoops/transitland-route-geometry-generator/actions/workflows/github-actions-on-tag.yaml/badge.svg)
## Generate your transitland route shapes from gtfs trips

This project aims to generate [transitland]() `gtfs routes` shapes from `gtfs trips` shapes.
This project aims to generate [transitland]("https://github.com/interline-io/transitland-server") `gtfs routes` shapes from `gtfs trips` shapes.

## Installation

### Go binary

`go install github.com/phoops/transitland-route-geometry-generator/...@latest`

### Github release - recommended

You can grab the latest release on this repository [releases]("https://github.com/phoops/transitland-route-geometry-generator/releases")

### Docker image

`phoops/transitland-route-geometry-generator`



`docker run run --rm -ti phoops/transitland-route-geometry-generator 1 -d postgres://transit:transit@db/gtfsdb?sslmode=disable`
## How it works?

On `gtfs` spec, we don't have a direct association between `shapes` and `routes`, in `transitland` domain is possibile to associate a `geometry` to a `route`.

In order to associate a `geometry` to a `transitland route`, we need to process the `route trips` and the `shapes` associated to the `trips`.

In order to keep thing simple, we choose the `longest geometry` of all the `trips` and promote that geometry to the geometry of the `route`.

This project depends on `postgresql` and `postgis` and we interact directly with the `transitland` database, so `transitland` schema is needed.

### Steps

- Fetch trips for a specific `gtfs` feed and `routes` (Both can be provided as input to the CLI)
- Choose the `longest` shape associated to the `trips` of the routes
- Take the `geometry` of chosen shape and promote that to `route` geometry
- Persit the `geometry` in `tl_route_geometries table

**The shapes generation is idempotent, so you can use the CLI freely in your workflow, without worring of breaking things, when the shapes geometry are updated by a new feed, they will be imported and the route shape is computed again**

## Usage

```bash
Generate geometries for your gtfs routes in transistland.
Uses your trips geometries in order to compute the route shape
More information at https://github.com/phoops/transitland-route-geometry-generator

Usage:
transitland-route-geometry-generator [command]

Available Commands:
completion generate the autocompletion script for the specified shell
generate Generate routes
help Help about any command
version Print the version

Flags:
-h, --help help for transitland-route-geometry-generator
-v, --verbose verbose output
```
### Generate routes
```
Usage:
transitland-route-geometry-generator generate [flags]

Flags:
-d, --database string postgres database connection string
-n, --dry-run dry run generation, without inserts
-h, --help help for generate
-r, --routes ints route ids to include in generation, all by default
```
The `-v` flag will output more informations about the process, also the raw `postgresql` queries made by the cli.
The `generate` command wants a single argument, representing the `id` of the `gtfs` feed, this id can be obtained querying `transitland`, or in the
database table `current_feeds`.
The `-d` flag is also required, you should specify a `postgresql` connection string, like `postgres://transit:transit@db/gtfsdb?sslmode=disable`.
The `-r` flag will restrict the `route` shapes generation only to specific route `ids`, routes should be separated by comma, ex: `-d 1,2,3,4`.
**tl;dr:**
`transitland-route-geometry-generator generate 1 -d "postgres://transit:transit@localhost/gtfsdb?sslmode=disable"`
### Dry run
If you want to only get the computed `shapes` for your routes, you can use the `-n` flag, this will skip the database write of `route shapes`.
The output will be a table like that
```bash
{"level":"info","ts":"2021-11-30T12:56:58.274+0100","caller":"commands/generator.go:50","msg":"starting generation","command":"generate","verbose":false,"dry-run":true,"feed_version_id":1}
+----------+--------------+------------------+
| ROUTE ID | DIRECTION ID | LONGEST SHAPE ID |
+----------+--------------+------------------+
| 1 | 0 | 4 |
| 1 | 1 | 2 |
| 2 | 0 | 1 |
| 2 | 1 | 8 |
+----------+--------------+------------------+
{"level":"info","ts":"2021-11-30T12:56:58.350+0100","caller":"commands/generator.go:88","msg":"dry run completed, run again without the n flag","command":"generate","verbose":false}
```
If you pass the `-v` flag, the output will contain also the raw `geometry` and the `centroid` of shape.
**tl;dr:**
`transitland-route-geometry-generator generate 1 -n -d "postgres://transit:transit@localhost/gtfsdb?sslmode=disable"`
2 changes: 1 addition & 1 deletion internal/commands/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var RouteIDs []int
func init() {
rootCmd.AddCommand(generateCmd)
generateCmd.Flags().BoolVarP(&DryRun, "dry-run", "n", false, "dry run generation, without inserts")
generateCmd.Flags().StringVarP(&DbConnectionString, "database", "d", "", "dry run generation, without inserts")
generateCmd.Flags().StringVarP(&DbConnectionString, "database", "d", "", "postgres database connection string")
generateCmd.Flags().IntSliceVarP(&RouteIDs, "routes", "r", []int{}, "route ids to include in generation, all by default")

err := generateCmd.MarkFlagRequired("database")
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ var rootCmd = &cobra.Command{
Use: "transitland-route-geometry-generator",
Short: "transitland-route-geometry-generator",
Long: `
Generate geoemtries for your gtfs routes in transistland.
Uses your trips geometries in order to compute their union as route shape
Generate geometries for your gtfs routes in transistland.
Uses your trips geometries in order to compute the route shape
More information at https://github.com/phoops/transitland-route-geometry-generator`,
}

Expand Down

0 comments on commit ac38778

Please sign in to comment.