From 8c356b7ca3f0aefd457e786560c7f447c688ca32 Mon Sep 17 00:00:00 2001 From: farhanW3 <132962163+farhanW3@users.noreply.github.com> Date: Fri, 8 Sep 2023 10:46:13 -0700 Subject: [PATCH] Added tag based image build workflow for gh actions (#107) * Added tag based image build workflow for gh actions * updated job name --- .github/workflows/tagBasedImageBuild.yml | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/tagBasedImageBuild.yml diff --git a/.github/workflows/tagBasedImageBuild.yml b/.github/workflows/tagBasedImageBuild.yml new file mode 100644 index 000000000..7fa5c2455 --- /dev/null +++ b/.github/workflows/tagBasedImageBuild.yml @@ -0,0 +1,40 @@ +name: Tag Based Image Build + +on: + create: # This listens to create events, which includes tag creations + +jobs: + buildImageForNewTag: + if: startsWith(github.ref, 'refs/tags/') # Only run this job when a tag is created + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Verify tag is on main branch + run: | + TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref }}) + MAIN_BRANCH_COMMIT=$(git rev-list -n 1 main) + if [ "$TAG_COMMIT" != "$MAIN_BRANCH_COMMIT" ]; then + echo "Tag is not on the main branch, aborting!" + exit 1 + fi + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and Push Docker Image + uses: docker/build-push-action@v2 + with: + context: . + target: prod + platforms: linux/amd64,linux/arm64 + push: true + tags: thirdweb/web3-api:${{ github.ref_name }} # Set the docker tag to the Git tag name