diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2b89a3f..ea743c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,14 +11,9 @@ on: - '.gitignore' - 'LICENSE' -permissions: - contents: write - pull-requests: read env: - ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:latest - docker_repo_addr: shayanghani/container-exporter:latest - docker_hub_user: shayanghani + ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:pr-${{github.run_id}} jobs: @@ -28,12 +23,6 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ env.docker_hub_user }} - password: ${{ secrets.DOCKER_TOKEN }} - - name: Login to GHCR uses: docker/login-action@v3 with: @@ -52,9 +41,7 @@ jobs: with: context: . push: true - tags: | - ${{env.ghcr_repo_addr}} - ${{env.docker_repo_addr}} + tags: ${{env.ghcr_repo_addr}} diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 1e7c593..f96f5c5 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -1,4 +1,4 @@ -name: CI for development branches +name: CI-development on: push: @@ -26,15 +26,12 @@ on: - '.gitignore' - 'LICENSE' -permissions: - contents: write - pull-requests: read env: - ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:latest + ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:${{github.action}}-${{github.run_id}} jobs: - probe: + build-and-check: runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2274be4..84de602 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,11 +14,20 @@ on: branches: - master +permissions: + contents: write + pull-requests: read + env: ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:latest - + docker_repo_addr: shayanghani/container-exporter + docker_hub_user: shayanghani + jobs: release: + outputs: + image_tag: ${{ steps.bump.outputs.new_tag }} + if: github.event_name != 'pull_request' && github.ref_name == 'master' runs-on: ubuntu-latest steps: @@ -35,4 +44,33 @@ jobs: uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 with: body: ${{ steps.bump.outputs.changelog }} - tag_name: ${{ steps.bump.outputs.new_tag }} \ No newline at end of file + tag_name: ${{ steps.bump.outputs.new_tag }} + + docker-push: + runs-on: ubuntu-latest + needs: release + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ env.docker_hub_user }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and Push to Dockerhub + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + "${{env.docker_repo_addr}}:${{ needs.release.outputs.image_tag }}" + "${{env.docker_repo_addr}}:latest" + \ No newline at end of file