From 52ae95e871eefcd6ad9b3a43914d5e8d7547f09c Mon Sep 17 00:00:00 2001 From: Marian Koreniuk Date: Thu, 13 Mar 2025 18:52:37 +0100 Subject: [PATCH] fix ci and test new workflow --- .github/workflows/pr.yml | 73 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 51 ++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..6033ec6c --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,73 @@ +name: Pull Request Workflow + +on: + pull_request: + types: [opened, synchronize, reopened] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build images + run: make build + env: + DOCKER_BUILDKIT: 1 + + - name: Tag and push images + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + BRANCH_NAME="test-pr${PR_NUMBER}" + git checkout -b ${BRANCH_NAME} + git push origin ${BRANCH_NAME} + + # Tag images with PR number + for image in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep ${IMAGE_NAME}); do + docker tag ${image} ${image}-pr${PR_NUMBER} + docker push ${image}-pr${PR_NUMBER} + done + + - name: Run tests + run: make test + + cleanup: + needs: build-and-test + if: github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Delete PR-tagged images + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + for image in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep ${IMAGE_NAME} | grep "pr${PR_NUMBER}"); do + docker rmi ${image} + docker push ${image} --delete + done \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..80701ffd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,51 @@ +name: Release Workflow + +on: + release: + types: [published] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + test-and-release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: make test + + - name: Build images + run: make build + env: + DOCKER_BUILDKIT: 1 + + - name: Tag and push release images + run: | + VERSION=${{ github.event.release.tag_name }} + for image in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep ${IMAGE_NAME}); do + docker tag ${image} ${image}:${VERSION} + docker push ${image}:${VERSION} + done + + - name: Create release notes + uses: softprops/action-gh-release@v1 + with: + files: | + README.md + CHANGELOG.md + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file