-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (57 loc) · 1.77 KB
/
station.yml
File metadata and controls
66 lines (57 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: API
on:
push:
branches: [ main, dev ]
paths:
- 'TrainStation/**'
- '.github/workflows/station.yml'
pull_request:
branches: [ main, dev ]
paths:
- 'TrainStation/**'
- '.github/workflows/station.yml'
release:
types: [published, created]
env:
DOCKER_IMAGE: trainprotocol/station
DOTNET_VERSION: 9
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Format version
id: format_version
run: |
commitHash=${GITHUB_SHA:0:7}
ts=$(date +%s)
version=$commitHash-$ts
echo "VERSION=$version" >> $GITHUB_ENV
- name: Sanitize branch name
id: sanitize_branch_name
run: |
sanitized_ref_name=$(echo "${GITHUB_REF_NAME}" | sed 's/[\/.]/-/g')
echo "SANITIZED_REF_NAME=$sanitized_ref_name" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: TrainStation/Dockerfile
push: ${{github.ref_name == 'main' || github.ref_name == 'dev'}}
build-args: |
DOTNET_VERSION=${{ env.DOTNET_VERSION }}
tags: |
${{ env.DOCKER_IMAGE }}:${{ env.SANITIZED_REF_NAME }}-${{ env.VERSION }}
${{ env.DOCKER_IMAGE }}:${{ env.SANITIZED_REF_NAME }}
cache-from: type=gha
cache-to: type=gha,mode=max