|
| 1 | +name: Build and Push Docker Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +env: |
| 9 | + DOCKERHUB_USERNAME: mmmay0722 |
| 10 | + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} |
| 11 | + REGISTRY: docker.io |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-push: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + timeout-minutes: 60 |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Docker Buildx |
| 23 | + uses: docker/setup-buildx-action@v3 |
| 24 | + |
| 25 | + - name: Log in to Docker Hub |
| 26 | + uses: docker/login-action@v3 |
| 27 | + with: |
| 28 | + registry: ${{ env.REGISTRY }} |
| 29 | + username: ${{ env.DOCKERHUB_USERNAME }} |
| 30 | + password: ${{ env.DOCKERHUB_TOKEN }} |
| 31 | + |
| 32 | + - name: Extract tag name |
| 33 | + id: extract_tag |
| 34 | + run: | |
| 35 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 36 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 37 | + echo "is_tag=true" >> $GITHUB_OUTPUT |
| 38 | + else |
| 39 | + TAG_NAME="latest" |
| 40 | + echo "is_tag=false" >> $GITHUB_OUTPUT |
| 41 | + fi |
| 42 | + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT |
| 43 | + echo "Extracted tag: $TAG_NAME" |
| 44 | +
|
| 45 | + - name: Build and push Docker image |
| 46 | + uses: docker/build-push-action@v5 |
| 47 | + timeout-minutes: 30 |
| 48 | + with: |
| 49 | + context: . |
| 50 | + file: ./Dockerfile |
| 51 | + push: true |
| 52 | + tags: ${{ env.REGISTRY }}/${{ env.DOCKERHUB_USERNAME }}/webqa-agent:${{ steps.extract_tag.outputs.tag_name }} |
| 53 | + cache-from: type=gha |
| 54 | + cache-to: type=gha,mode=max |
| 55 | + platforms: linux/amd64 |
| 56 | + provenance: false |
| 57 | + sbom: false |
| 58 | + |
| 59 | + create-release: |
| 60 | + needs: build-and-push |
| 61 | + runs-on: ubuntu-latest |
| 62 | + if: startsWith(github.ref, 'refs/tags/v') |
| 63 | + permissions: |
| 64 | + contents: write |
| 65 | + discussions: write |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Checkout code |
| 69 | + uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + |
| 73 | + - name: Extract tag name |
| 74 | + id: extract_tag |
| 75 | + run: | |
| 76 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 77 | + echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT |
| 78 | + echo "Current tag: $TAG_NAME" |
| 79 | +
|
| 80 | + - name: Generate changelog |
| 81 | + id: changelog |
| 82 | + run: | |
| 83 | + CURRENT_TAG=${{ steps.extract_tag.outputs.tag_name }} |
| 84 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "") |
| 85 | +
|
| 86 | + echo "## 🚀 Release $CURRENT_TAG" > CHANGELOG.md |
| 87 | + echo "" >> CHANGELOG.md |
| 88 | + echo "### 📦 Docker Images" >> CHANGELOG.md |
| 89 | + echo "- \`${{ env.DOCKERHUB_USERNAME }}/webqa-agent:$CURRENT_TAG\`" >> CHANGELOG.md |
| 90 | + echo "" >> CHANGELOG.md |
| 91 | +
|
| 92 | + if [ -n "$PREVIOUS_TAG" ]; then |
| 93 | + echo "### 📝 Changes since $PREVIOUS_TAG" >> CHANGELOG.md |
| 94 | + git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..$CURRENT_TAG >> CHANGELOG.md |
| 95 | + else |
| 96 | + echo "### 📝 Initial Release" >> CHANGELOG.md |
| 97 | + echo "This is the initial release of WebQA Agent." >> CHANGELOG.md |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Create GitHub Release |
| 101 | + uses: softprops/action-gh-release@v1 |
| 102 | + with: |
| 103 | + tag_name: ${{ steps.extract_tag.outputs.tag_name }} |
| 104 | + name: Release ${{ steps.extract_tag.outputs.tag_name }} |
| 105 | + body_path: CHANGELOG.md |
| 106 | + draft: false |
| 107 | + prerelease: false |
| 108 | + generate_release_notes: true |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + |
| 112 | + notify: |
| 113 | + needs: [build-and-push, create-release] |
| 114 | + runs-on: ubuntu-latest |
| 115 | + if: always() |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Notify build status |
| 119 | + run: | |
| 120 | + if [ "${{ needs.build-and-push.result }}" == "success" ]; then |
| 121 | + echo "✅ Docker image built and pushed successfully!" |
| 122 | + echo "✅ Both versioned and latest tags have been updated!" |
| 123 | + else |
| 124 | + echo "❌ Docker image build failed!" |
| 125 | + exit 1 |
| 126 | + fi |
| 127 | +
|
| 128 | + if [ "${{ needs.create-release.result }}" == "success" ] || [ "${{ needs.create-release.result }}" == "skipped" ]; then |
| 129 | + echo "✅ Release process completed successfully!" |
| 130 | + else |
| 131 | + echo "❌ Release process failed!" |
| 132 | + fi |
0 commit comments