Skip to content

Commit

Permalink
ci: test container before push (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan authored May 24, 2024
1 parent 79d8c1b commit 7a7b4af
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 58 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: CI

on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- main
Expand All @@ -28,10 +25,7 @@ jobs:
version: 2.15.2
- run: env | sort
- run: make dev
- run: make lint
- run: make test
- run: make doc
- run: make build
- run: make lint test doc build
strategy:
matrix:
os:
Expand Down
60 changes: 45 additions & 15 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
name: DevContainer

on:
pull_request:
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
push:
branches:
- main
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
workflow_dispatch: null

concurrency:
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
dev-container-publish:
permissions:
packages: write
runs-on: ubuntu-22.04
steps:
- run: env | sort
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- run: docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io
- run: |
Expand All @@ -18,26 +36,38 @@ jobs:
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-from type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
--load \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
--target dev
- run: |
docker run --rm \
-e CI=true \
-v ${PWD}:/workspace \
ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
make dev lint test doc build
- run: |
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
--load \
--tag ghcr.io/${{ github.repository }}:py${{ matrix.python-version }} \
--target prod
- run: docker run --rm ghcr.io/${{ github.repository }}:py${{ matrix.python-version }}
- if: github.event_name != 'pull_request'
run: |
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-to type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
--target dev
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
on:
push:
branches:
- main
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
workflow_dispatch: null
- '3.8'
- '3.9'
- '3.10'
- '3.11'
- '3.12'
28 changes: 25 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
packages: write
runs-on: ubuntu-22.04
steps:
- run: env | sort
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- run: docker login -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ghcr.io
- run: |
Expand All @@ -54,9 +55,22 @@ jobs:
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-from type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
--load \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }}-${{ github.ref_name }} \
--target dev
- run: |
docker run --rm \
-e CI=true \
-v ${PWD}:/workspace \
ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
make dev lint test doc build
- run: |
docker buildx build . \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-to type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }} \
--tag ghcr.io/${{ github.repository }}/dev:py${{ matrix.python-version }}-${{ github.ref_name }} \
Expand All @@ -65,9 +79,17 @@ jobs:
docker buildx build . \
--build-arg SCM_VERSION=${{ github.ref_name }} \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--cache-from type=registry,ref=ghcr.io/${{ github.repository }}/dev-cache:py${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
--provenance false \
--load \
--tag ghcr.io/${{ github.repository }}:py${{ matrix.python-version }} \
--tag ghcr.io/${{ github.repository }}:py${{ matrix.python-version }}-${{ github.ref_name }} \
--target prod
- run: docker run --rm ghcr.io/${{ github.repository }}:py${{ matrix.python-version }}
- run: |
docker buildx build . \
--build-arg SCM_VERSION=${{ github.ref_name }} \
--build-arg PYTHON_VERSION=${{ matrix.python-version }} \
--file .devcontainer/Dockerfile \
--push \
--tag ghcr.io/${{ github.repository }}:py${{ matrix.python-version }} \
--tag ghcr.io/${{ github.repository }}:py${{ matrix.python-version }}-${{ github.ref_name }} \
Expand Down
19 changes: 18 additions & 1 deletion .gitlab/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ dev-container-publish:
- .gitlab/workflows/devcontainer.yml
if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "web"
- changes:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .gitlab/workflows/devcontainer.yml
if: $CI_PIPELINE_SOURCE == 'merge_request_event'
script:
- docker login -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD} ${CI_REGISTRY}
- docker context create builder
Expand All @@ -24,9 +29,21 @@ dev-container-publish:
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
--load \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--target dev
- |
docker run --rm \
-e CI=true \
-v ${PWD}:/workspace \
${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
make dev lint test doc build
- |
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--target dev
Expand Down
27 changes: 24 additions & 3 deletions .gitlab/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ container-publish:
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
--load \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--target dev
- |
docker run --rm \
-e CI=true \
-v ${PWD}:/workspace \
${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
make dev lint test doc build
- |
docker buildx build . \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}/dev:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
Expand All @@ -61,9 +74,17 @@ container-publish:
docker buildx build . \
--build-arg SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/dev-cache:py${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
--provenance false \
--load \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
--target prod
- docker run --rm ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION}
- |
docker buildx build . \
--build-arg SCM_VERSION=${CI_COMMIT_TAG} \
--build-arg PYTHON_VERSION=${PYTHON_VERSION} \
--file .devcontainer/Dockerfile \
--push \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION} \
--tag ${CI_REGISTRY_IMAGE}:py${PYTHON_VERSION}-${CI_COMMIT_TAG} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: CI

on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- main
Expand All @@ -29,10 +26,7 @@ jobs:
version: 2.15.2
- run: env | sort
- run: make dev
- run: make lint
- run: make test
- run: make doc
- run: make build
- run: make lint test doc build
strategy:
matrix:
os:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
[% from pathjoin("includes", "version_compare.jinja") import version_between -%]
name: DevContainer

on:
pull_request:
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
push:
branches:
- main
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
workflow_dispatch: null

concurrency:
cancel-in-progress: true
group: {{ '${{ github.workflow }}-${{ github.ref }}' }}

jobs:
dev-container-publish:
permissions:
packages: write
runs-on: ubuntu-22.04
steps:
- run: env | sort
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- run: docker login -u {{ '${{ github.actor }}' }} -p {{ '${{ secrets.GITHUB_TOKEN }}' }} ghcr.io
- run: |
Expand All @@ -19,36 +37,48 @@ jobs:
docker buildx build . \
--build-arg PYTHON_VERSION={{ '${{ matrix.python-version }}' }} \
--cache-from type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }} \
--file .devcontainer/Dockerfile \
--load \
--tag ghcr.io/{{ '${{ github.repository }}' }}/dev:py{{ '${{ matrix.python-version }}' }} \
--target dev
- run: |
docker run --rm \
-e CI=true \
-v ${PWD}:/workspace \
ghcr.io/{{ '${{ github.repository }}' }}/dev:py{{ '${{ matrix.python-version }}' }} \
make dev lint test doc build
- run: |
docker buildx build . \
--build-arg PYTHON_VERSION={{ '${{ matrix.python-version }}' }} \
--file .devcontainer/Dockerfile \
--load \
--tag ghcr.io/{{ '${{ github.repository }}' }}:py{{ '${{ matrix.python-version }}' }} \
--target prod
- run: docker run --rm ghcr.io/{{ '${{ github.repository }}' }}:py{{ '${{ matrix.python-version }}' }}
- if: github.event_name != 'pull_request'
run: |
docker buildx build . \
--build-arg PYTHON_VERSION={{ '${{ matrix.python-version }}' }} \
--cache-to type=registry,ref=ghcr.io/{{ '${{ github.repository }}' }}/dev-cache:py{{ '${{ matrix.python-version }}' }},mode=max \
--file .devcontainer/Dockerfile \
--provenance false \
--push \
--tag ghcr.io/{{ '${{ github.repository }}' }}/dev:py{{ '${{ matrix.python-version }}' }} \
--target dev
strategy:
matrix:
python-version:
[%- if version_between("3.8", min_py, max_py) %]
- "3.8"
- '3.8'
[%- endif %]
[%- if version_between("3.9", min_py, max_py) %]
- "3.9"
- '3.9'
[%- endif %]
[%- if version_between("3.10", min_py, max_py) %]
- "3.10"
- '3.10'
[%- endif %]
[%- if version_between("3.11", min_py, max_py) %]
- "3.11"
- '3.11'
[%- endif %]
[%- if version_between("3.12", min_py, max_py) %]
- "3.12"
- '3.12'
[%- endif %]
on:
push:
branches:
- main
paths:
- .devcontainer/Dockerfile
- .devcontainer/Dockerfile.dockerignore
- .github/workflows/devcontainer.yml
workflow_dispatch: null
Loading

0 comments on commit 7a7b4af

Please sign in to comment.