Skip to content

Separate source code for each version #76

Separate source code for each version

Separate source code for each version #76

Workflow file for this run

name: CI
on:
pull_request:
paths:
- .github/workflows/ci.yaml
- src/**
- test/**
push:
paths:
- .github/workflows/ci.yaml
- src/**
- test/**
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
versions:
runs-on: ubuntu-latest
outputs:
json: ${{ steps.versions.outputs.value }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- name: List versions
id: versions
run: |
require "json"
versions = Dir["src/*"].map { |path| File.basename(path) }
puts "::set-output name=value::#{versions.to_json}"
shell: ruby {0}
build-and-test:
runs-on: ubuntu-latest
needs:
- versions
strategy:
fail-fast: true
matrix:
version: ${{ fromJSON(needs.versions.outputs.json) }}
env:
MONGO_VERSION: ${{ matrix.version }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- uses: docker/build-push-action@v3
with:
context: ./src/${{ matrix.version }}
load: true
tags: |
a2ikm/sharded-mongo:${{ matrix.version }}-test
build-args: |
MONGO_VERSION=${{ matrix.version }}
- name: Run tests
run: |
docker run --rm \
--volume "$(pwd)/test/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d" \
--volume "$(pwd)/test:/test" \
a2ikm/sharded-mongo:${MONGO_VERSION}-test bash /test/test.sh
release:
if: ${{ github.ref_name == 'main' }}
runs-on: ubuntu-latest
needs:
- build-and-test
strategy:
matrix:
version: ${{ fromJSON(needs.versions.outputs.json) }}
env:
MONGO_VERSION: ${{ matrix.version }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- name: Generate tags
id: tags
run: |
require "json"
version = ENV.fetch("MONGO_VERSION")
latest = Dir["src/*"].map { |path| File.basename(path) }.sort.last
tags = [
"a2ikm/sharded-mongo:#{version}",
]
if version == latest
tags << "a2ikm/sharded-mongo:latest"
end
puts "::set-output name=value::#{tags.join(",")}"
shell: ruby {0}
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/build-push-action@v3
with:
context: ./src/${{ matrix.version }}
push: true
tags: ${{ steps.tags.outputs.value }}
build-args: |
MONGO_VERSION=${{ matrix.version }}
platforms: |
linux/amd64
linux/arm64