-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (63 loc) · 2.21 KB
/
build.yml
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
67
68
69
70
71
72
73
74
75
name: Build
on: [ push, pull_request, workflow_dispatch ]
env:
REGISTRY: ghcr.io
jobs:
# TODO: DRY w/release.yml
setup:
runs-on: ubuntu-latest
steps:
# See https://github.com/docker/build-push-action/blob/v2.10.0/TROUBLESHOOTING.md#repository-name-must-be-lowercase
- name: Sanitize image name
uses: actions/github-script@v6
id: image-name
with:
result-encoding: string
script: return '${{ env.REGISTRY }}/${{ github.repository }}'.toLowerCase()
- name: Get short SHA
run: |
echo SHORT_SHA="${GITHUB_SHA:0:7}" >> $GITHUB_ENV
- name: Get build start time
run: |
echo BUILD_TIMESTAMP="$(date --utc --iso-8601=seconds)" >> $GITHUB_ENV
outputs:
base_image_name: ${{ steps.image-name.outputs.result }}
build_image: ${{ steps.image-name.outputs.result }}:${{ env.SHORT_SHA }}
test:
if: github.event_name != 'release'
needs: [ setup ]
runs-on: ubuntu-latest
permissions:
packages: write
env:
BUILD_IMAGE: ${{ needs.setup.outputs.build_image }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Start solr
run: docker compose up --build -d app solr
- name: Wait for solr to start
run: docker compose exec solr wait-for-solr.sh
- name: Run tests
run: docker compose exec --env CI=$CI app rake
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ env.BUILD_IMAGE }}
build-args: |
BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }}
BUILD_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
DOCKER_TAG=${{ env.BUILD_IMAGE }}
GIT_BRANCH=${{ github.ref_name }}
GIT_COMMIT=${{ github.sha }}
GIT_URL=${{ github.repositoryUrl }}
outputs:
build_image: ${{ env.BUILD_IMAGE }}