Skip to content

Commit eba6aff

Browse files
[IMP] Add pushing PR images to be able to test it correctly
1 parent 80ddfb7 commit eba6aff

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

.github/workflows/ci.yaml

+18-11
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ jobs:
1616
- uses: actions/checkout@v2
1717
- uses: actions/setup-python@v1
1818
- name: Set PY
19-
run:
20-
echo "PY=$(python -c 'import hashlib,
21-
sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')"
22-
>> $GITHUB_ENV
19+
run: |
20+
echo "PY=$(python -c 'import hashlib,sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
2321
- uses: actions/cache@v1
2422
with:
2523
path: ~/.cache/pre-commit
@@ -32,7 +30,6 @@ jobs:
3230
strategy:
3331
fail-fast: false
3432
matrix:
35-
# Test modern Odoo versions with latest Postgres version
3633
pg_version:
3734
- "16"
3835
- "15"
@@ -45,29 +42,39 @@ jobs:
4542
env:
4643
# Indicates what's the equivalent to tecnativa/postgres-autoconf:latest image
4744
LATEST_RELEASE: "16-alpine"
48-
# Variables found by default in Docker Hub builder
4945
DOCKER_REPO: tecnativa/postgres-autoconf
5046
DOCKER_TAG: ${{ matrix.pg_version }}-alpine
5147
GIT_SHA1: ${{ github.sha }}
48+
IS_PR: ${{ github.event_name == 'pull_request' }}
5249
steps:
53-
# Prepare
5450
- uses: actions/checkout@v2
5551
- uses: actions/setup-python@v1
5652
- run: pip install -r tests/ci-requirements.txt
53+
5754
# Build images
5855
- run: ./hooks/build
5956
# Test
6057
- run: python -m unittest tests.test -v
58+
- name: Set Docker Tag
59+
run: |
60+
if [ "${{ env.IS_PR }}" = "true" ]; then
61+
echo "DOCKER_TAG=${{ matrix.pg_version }}-test-pr${{ github.event.number }}" >> $GITHUB_ENV
62+
else
63+
echo "DOCKER_TAG=${{ matrix.pg_version }}-alpine" >> $GITHUB_ENV
64+
fi
65+
- name: Tag Docker Image for PR
66+
if: env.IS_PR
67+
run: docker tag ${{ env.DOCKER_REPO }}:${{ matrix.pg_version }}-alpine ${{ env.DOCKER_REPO }}:${{ env.DOCKER_TAG }}
6168
# Push
62-
- name: push to docker hub
63-
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && github.ref == 'refs/heads/master'
69+
- name: Push Docker Image to Docker Hub
70+
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && (env.IS_PR || github.ref == 'refs/heads/master')
6471
env:
6572
REGISTRY_HOST: docker.io
6673
REGISTRY_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
6774
REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_LOGIN }}
6875
run: ./hooks/push
69-
- name: push to github registry
70-
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && github.ref == 'refs/heads/master'
76+
- name: Push Docker Image to GitHub Registry
77+
if: github.repository == 'Tecnativa/docker-postgres-autoconf' && (env.IS_PR || github.ref == 'refs/heads/master')
7178
env:
7279
REGISTRY_HOST: ghcr.io
7380
REGISTRY_TOKEN: ${{ secrets.BOT_TOKEN }}

0 commit comments

Comments
 (0)