Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for version number #4

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,52 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set APP_VERSION environment
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | \
cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
- name: Set BUILD_TIME env
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: linux
goarch: amd64
extra_files: config.yaml.example README.md
ldflags: -X "main.Version={{ env.APP_VERSION }} {{ env.BUILD_TIME }}"

release-linux-arm7:
name: release linux/arm-7
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set APP_VERSION environment
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | \
cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
- name: Set BUILD_TIME env
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: linux
goarch: arm
goarm: 7
extra_files: config.yaml.example README.md
ldflags: -X "main.Version={{ env.APP_VERSION }} {{ env.BUILD_TIME }}"

release-darwin-amd64:
name: release darwin/amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set APP_VERSION environment
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | \
cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
- name: Set BUILD_TIME env
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: darwin
goarch: amd64
extra_files: config.yaml.example README.md
ldflags: -X "main.Version={{ env.APP_VERSION }} {{ env.BUILD_TIME }}"
9 changes: 9 additions & 0 deletions uk-rail-schedule-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

type APIStatus struct {
Version string
ScheduleFileCount int64
VSTPCount int64
}
Expand Down Expand Up @@ -240,7 +241,14 @@ func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error {

var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}
var ErrUnprocessable = &ErrResponse{HTTPStatusCode: 422, StatusText: "Unprocessable entity."}

// Global version variable - set at build time
var version string

// Global database variable
var db *gorm.DB

// Global logger variable
var logger *slog.Logger

// Refreshing the database is a long running process - this variable and the following functions are
Expand Down Expand Up @@ -522,6 +530,7 @@ func combineDateAndTime(date int64, wtt_time string) (timestamp int64, err error
func dbGetStatus() (APIStatus, error) {

var status APIStatus
status.Version = version

if db == nil {
logger.Error("Cannot get schedules - db does not exist")
Expand Down