@@ -3,7 +3,7 @@ name: Build and push gtfs-rt-archiver-v3 image
33on :
44 push :
55 branches :
6- - ' main'
6+ - main
77 paths :
88 - ' .github/workflows/build-gtfs-rt-archiver-v3-image.yml'
99 - ' services/gtfs-rt-archiver-v3/**'
@@ -16,47 +16,95 @@ concurrency:
1616 group : ${{ github.workflow }}-${{ github.ref }}
1717 cancel-in-progress : ${{ github.ref != 'refs/heads/main' }}
1818
19+ env :
20+ PYTHON_VERSION : ' 3.11'
21+ POETRY_VERSION : ' 2.0.1'
22+
1923jobs :
20- check :
21- name : Run static checkers
24+ lint :
25+ name : Lint
2226 runs-on : ubuntu-latest
23- env :
24- CALITP_BUCKET__GTFS_RT_PARSED : gs://some-test-bucket
25- CALITP_BUCKET__GTFS_RT_VALIDATION : gs://some-test-bucket
26- GTFS_RT_VALIDATOR_VERSION : v0.0.0
2727 steps :
28- - uses : actions/checkout@v2
29- - uses : actions/setup-python@v4
28+ - name : Checkout
29+ uses : actions/checkout@v4
30+
31+ - name : Setup Graphviz
32+ uses : ts-graphviz/setup-graphviz@v2
33+
34+ - name : Setup Python
35+ uses : actions/setup-python@v5
36+ with :
37+ python-version : ${{ env.PYTHON_VERSION }}
38+
39+ - name : Cache poetry
40+ uses : actions/cache@v3
41+ with :
42+ path : ~/.cache/pypoetry
43+ key : poetry-cache-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-poetry-${{ env.POETRY_VERSION }}
44+
45+ - name : Setup Poetry
46+ uses : abatilo/actions-poetry@v3
47+ with :
48+ poetry-version : ${{ env.POETRY_VERSION }}
49+
50+ - name : Cache python packages
51+ uses : actions/cache@v3
3052 with :
31- python-version : ' 3.9'
32- - run : curl -sSL https://install.python-poetry.org | python -
33- - run : cd services/gtfs-rt-archiver-v3 && poetry install && poetry run mypy .
53+ path : ~/.local
54+ key : python-cache-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-lock-${{ hashFiles('poetry.lock') }}-${{ hashFiles('.github/workflows/*.yml') }}
3455
35- build_push :
36- name : Package docker image
56+ - name : Install dependencies
57+ working-directory : services/gtfs-rt-archiver-v3
58+ run : poetry install
59+
60+ - name : Run mypy
61+ working-directory : services/gtfs-rt-archiver-v3
62+ run : poetry run mypy .
63+
64+ docker :
65+ name : Push docker image
3766 runs-on : ubuntu-latest
38- needs : [check]
67+ permissions :
68+ contents : read
69+ packages : write
70+ attestations : write
71+ id-token : write
3972 steps :
40- - uses : actions/checkout@v2
41- - uses : docker/login-action@v1
73+ - name : Checkout
74+ uses : actions/checkout@v4
75+
76+ - name : Set up Docker Buildx
77+ uses : docker/setup-buildx-action@v3
78+
79+ - name : Login to GitHub Repository
80+ uses : docker/login-action@v3
4281 with :
4382 registry : ghcr.io
4483 username : ${{ github.actor }}
4584 password : ${{ secrets.GITHUB_TOKEN }}
46- - uses : actions/setup-python@v4
85+
86+ - name : Setup Python
87+ uses : actions/setup-python@v5
4788 with :
48- python-version : ' 3.10'
49- - run : curl -sSL https://install.python-poetry.org | python -
50- # from https://forcepush.tech/python-package-ci-cd-with-git-hub-actions
51- - name : Get image tag from pyproject.toml and commit SHA
52- run : |
53- cd services/gtfs-rt-archiver-v3
54- PROJECT_VERSION=$(poetry version --short)
55- echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
89+ python-version : ${{ env.PYTHON_VERSION }}
90+
91+ - name : Setup Poetry
92+ uses : abatilo/actions-poetry@v3
93+ with :
94+ poetry-version : ${{ env.POETRY_VERSION }}
95+
96+ - name : Get image tag from poetry
97+ working-directory : services/gtfs-rt-archiver-v3
98+ run : echo "PROJECT_VERSION=$(poetry version --short)" >> $GITHUB_ENV
99+
100+ - name : Get short GitHub SHA
101+ run : echo "GITHUB_SHA_SHORT=${GITHUB_SHA:0:6}" >> $GITHUB_ENV
56102
57- echo "GITHUB_SHA_SHORT=${GITHUB_SHA:0:6}" >> $GITHUB_ENV
58- - uses : docker/build-push-action@v2
103+ - name : Build and Push
104+ uses : docker/build-push-action@v6
59105 with :
60106 context : services/gtfs-rt-archiver-v3
61- push : ${{ github.ref == 'refs/heads/main' }}
62- tags : ghcr.io/${{github.repository}}/gtfs-rt-archiver-v3:${{env.PROJECT_VERSION}}-${{env.GITHUB_SHA_SHORT}}
107+ push : true
108+ tags : ghcr.io/${{ github.repository }}/gtfs-rt-parser-v2:${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'latest' || 'development' }}
109+ cache-from : type=registry,ref=ghcr.io/${{ github.repository }}/gtfs-rt-parser-v2:${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && env.PROJECT_VERSION || 'development' }}${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && '-' || '' }}${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && env.GITHUB_SHA_SHORT || '' }}
110+ cache-to : type=inline
0 commit comments