diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 1a06c0e0..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: ci - -on: - push: - branches: - - main - -jobs: - test_image: - uses: ./.github/workflows/lib_test_image.yml - with: - cache-from: type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest - - tests: - needs: test_image - uses: ./.github/workflows/lib_tests.yml - - testscleanup: - needs: tests - uses: ./.github/workflows/lib_test_cleanup.yml - - push: - needs: tests - uses: ./.github/workflows/lib_push_image.yml - with: - tags: ghcr.io/${{ github.repository }}:${{ github.run_number }},ghcr.io/${{ github.repository }}:latest - cache-from: | - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ github.ref_name }}-amd64 - cache-to: type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest,mode=max diff --git a/.github/workflows/build_dev.yml b/.github/workflows/build_dev.yml deleted file mode 100644 index b8a79325..00000000 --- a/.github/workflows/build_dev.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: ci dev - -on: - push: - branches: - - dev - - dev-* - -jobs: - test_image: - uses: ./.github/workflows/lib_test_image.yml - with: - cache-from: | - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ github.ref_name }} - - tests: - needs: test_image - uses: ./.github/workflows/lib_tests.yml - - testscleanup: - needs: tests - uses: ./.github/workflows/lib_test_cleanup.yml - - push: - needs: tests - uses: ./.github/workflows/lib_push_image.yml - with: - tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }} - cache-from: | - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ github.ref_name }} - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ github.ref_name }}-amd64 - cache-to: type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ github.ref_name }},mode=max diff --git a/.github/workflows/lib_test_image.yml b/.github/workflows/build_image.yml similarity index 85% rename from .github/workflows/lib_test_image.yml rename to .github/workflows/build_image.yml index ce9ddb98..2e06c823 100644 --- a/.github/workflows/lib_test_image.yml +++ b/.github/workflows/build_image.yml @@ -6,6 +6,9 @@ permissions: on: workflow_call: inputs: + build-tag: + required: true + type: string cache-from: required: true type: string @@ -30,10 +33,10 @@ jobs: file: dev/Dockerfile platforms: linux/amd64 outputs: type=docker,dest=/tmp/myimage.tar - tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }} + tags: ghcr.io/${{ github.repository }}:${{ inputs.build-tag }} cache-from: ${{ inputs.cache-from }} # specific "cache-to" here as otherwise it would override the latest multi-platform cache with this amd64-only one - cache-to: type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ github.ref_name }}-amd64,mode=max + cache-to: type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ inputs.build-tag }}-amd64,mode=max - name: Upload artifact uses: actions/upload-artifact@v3 diff --git a/.github/workflows/build_pr.yml b/.github/workflows/build_pr.yml index 01ed1902..ae11cee8 100644 --- a/.github/workflows/build_pr.yml +++ b/.github/workflows/build_pr.yml @@ -1,24 +1,45 @@ -name: ci pr +name: pull request ci on: - push: - branches-ignore: + pull_request: + branches: - main - - dev - - dev-* - + jobs: - test_image: - uses: ./.github/workflows/lib_test_image.yml + tag: + name: get latest tag + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.doit.outputs.new }} + steps: + - uses: actions/checkout@v3 + - id: doit + env: + FALLBACK_VERSION: "1.0.0" + run: | + latest=$(git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/v*" | cut -b 2-) + if [[ $latest -eq "" ]]; then + latest=$FALLBACK_VERSION + echo "No tag found, using fallback: $latest" + fi + new=$(echo $latest | awk -F. '{OFS="."; $NF+=1; print $0}') + echo "new=$new" >> $GITHUB_OUTPUT + + build_img: + needs: tag + uses: ./.github/workflows/build_image.yml with: + build-tag: ${{ needs.tag.outputs.tag }}-${{ github.run_id }}-dev cache-from: | type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest - type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ github.ref_name }} + type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ needs.tag.outputs.tag }}-${{ github.run_id }}-dev tests: - needs: test_image - uses: ./.github/workflows/lib_tests.yml - + needs: [tag, build_img] + uses: ./.github/workflows/run_tests.yml + with: + build-tag: ${{ needs.tag.outputs.tag }}-${{ github.run_id }}-dev + testscleanup: - needs: tests - uses: ./.github/workflows/lib_test_cleanup.yml + needs: tests + uses: ./.github/workflows/test_cleanup.yml diff --git a/.github/workflows/lib_push_image.yml b/.github/workflows/lib_push_image.yml deleted file mode 100644 index 77f7bd36..00000000 --- a/.github/workflows/lib_push_image.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: push image - -on: - workflow_call: - inputs: - cache-from: - required: true - type: string - cache-to: - required: true - type: string - tags: - required: true - type: string - -jobs: - doit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to GHCR - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v3 - with: - file: dev/Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ inputs.tags }} - cache-from: ${{ inputs.cache-from }} - cache-to: ${{ inputs.cache-to }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..08e43b23 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,62 @@ +name: release tag + +on: + release: + types: + - [created] + +jobs: + tag: + runs-on: ubuntu-latest + name: get latest tag + outputs: + tag: ${{ steps.doit.outputs.new }} + steps: + - id: doit + $run: echo "new=$(echo ${{ github.ref_name }} | cut -b 2-)" >> $GITHUB_OUTPUT + + build_img: + needs: get_tag + uses: ./.github/workflows/build_image.yml + with: + build-tag: ${{ needs.tag.outputs.tag }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest + + tests: + needs: [tag, test_image] + uses: ./.github/workflows/run_tests.yml + with: + build-tag: ${{ needs.tag.outputs.tag }} + + testscleanup: + needs: [tag, tests] + uses: ./.github/workflows/test_cleanup.yml + with: + build-tag: ${{ needs.tag.outputs.tag }} + + push: + needs: [tag, tests] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GHCR + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v3 + with: + file: dev/Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/${{ github.repository }}:${{ github.run_number }},ghcr.io/${{ github.repository }}:${{ needs.tag.outputs.tag }} + cache-from: | + type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest + type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:${{ needs.tag.outputs.tag }}-amd64 + cache-to: type=registry,ref=ghcr.io/${{ github.repository }}-builder-cache:latest,mode=max diff --git a/.github/workflows/lib_tests.yml b/.github/workflows/run_tests.yml similarity index 82% rename from .github/workflows/lib_tests.yml rename to .github/workflows/run_tests.yml index f5b3ab3e..f6d4438f 100644 --- a/.github/workflows/lib_tests.yml +++ b/.github/workflows/run_tests.yml @@ -2,6 +2,10 @@ name: tests on: workflow_call: + inputs: + build-tag: + required: true + type: string jobs: style: @@ -33,15 +37,14 @@ jobs: services: mysql: - image: mysql:5 - env: - MYSQL_ROOT_PASSWORD: root + image: mysql:8 ports: - 8877:3306 # needed because the container does not provide a healthcheck - options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries=5 + options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=root --entrypoint sh mysql -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + postgres: - image: postgres:10 + image: postgres:15 env: POSTGRES_USER: root POSTGRES_PASSWORD: root @@ -59,15 +62,14 @@ jobs: path: /tmp - name: Load Docker images from previous workflows - run: | - docker load --input /tmp/myimage.tar + run: docker load --input /tmp/myimage.tar - name: run tests run: | docker run --network host \ -e SURF_DATABASE_URL=${{ matrix.database.url }} \ -v $(pwd)/cov/:/report \ - ghcr.io/${{ github.repository }}:${{ github.ref_name }} \ + ghcr.io/${{ github.repository }}:${{ inputs.build-tag }} \ sh -c 'pip install -r requirements_test.txt && pytest -n4 --cov --cov-report=xml:/report/coverage.xml' - uses: codecov/codecov-action@v3 diff --git a/.github/workflows/lib_test_cleanup.yml b/.github/workflows/test_cleanup.yml similarity index 100% rename from .github/workflows/lib_test_cleanup.yml rename to .github/workflows/test_cleanup.yml