-
Notifications
You must be signed in to change notification settings - Fork 101
98 lines (84 loc) · 3.13 KB
/
build-docker-image.yaml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Build hydra image
on:
pull_request_target:
types: [opened, synchronize, reopened]
paths:
- 'docker/env/Dockerfile'
- 'docker/env/build_n_push.sh'
- 'requirements.in'
- 'requirements.txt'
permissions:
actions: write
contents: write
jobs:
check_org_membership:
runs-on: ubuntu-latest
outputs:
isTeamMember: ${{ steps.teamAffiliation.outputs.isTeamMember }}
steps:
- name: Check user for team affiliation
uses: tspascoal/get-user-teams-membership@v3
if: github.actor != 'renovate[bot]'
id: teamAffiliation
with:
GITHUB_TOKEN: ${{ secrets.AUTO_BACKPORT_TOKEN }}
username: ${{ github.actor }}
team: 'dev'
build_image:
needs: check_org_membership
if: github.actor == 'renovate[bot]' || (needs.check_org_membership.outputs.isTeamMember == 'true' && contains(github.event.pull_request.labels.*.name, 'New Hydra Version'))
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
- name: Check if docker image is already built
run: |
git fetch origin master
commits_headlines=$(git log origin/master..HEAD --pretty=format:"%s")
if [[ "$commits_headlines" == *"chore(hydra): create image"* ]]; then
echo "Docker image already built"
exit 0
else
echo "Docker image not built yet"
fi
env:
GH_TOKEN: ${{ secrets. GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install uv==0.2.24
- name: Generate a random name based on PR
run: |
docker_version=$(cut -d'-' -f1 ./docker/env/version | awk -F. '{print $1"."$2+1}')
sha=$(echo "${{ github.sha }}" | cut -c1-7)
echo "${docker_version}-PR${{ github.event.number }}-${sha}" > ./docker/env/version
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
run: |
./docker/env/build_n_push.sh
- name: Configure Git
run: |
git config --global user.name 'scylla-sct[bot]'
git config --global user.email 'scylla-sct[bot]@users.noreply.github.com'
- name: Commit changes
run: |
git add -u
git commit -m "chore(hydra): create image $( cat ./docker/env/version )"
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}