|
| 1 | +name: Build & Publish Multi-Arch Appium Image |
| 2 | + |
| 3 | +on: |
| 4 | + # Manual trigger (custom tag optional) |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + tag: |
| 8 | + description: "Image tag (default: commit SHA)" |
| 9 | + type: string |
| 10 | + required: false |
| 11 | + default: "" |
| 12 | + push: |
| 13 | + description: "Push image to registry" |
| 14 | + type: boolean |
| 15 | + required: false |
| 16 | + default: false |
| 17 | + push: |
| 18 | + branches: ["**"] |
| 19 | + tags: ["*"] |
| 20 | + pull_request: |
| 21 | + |
| 22 | +jobs: |
| 23 | + prepare: |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + outputs: |
| 26 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 27 | + tag: ${{ steps.set-tag.outputs.tag }} |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - id: set-tag |
| 32 | + name: Compute image tag |
| 33 | + run: | |
| 34 | + TAG_INPUT='${{ github.event.inputs.tag }}' |
| 35 | + if [[ -n "$TAG_INPUT" ]]; then |
| 36 | + TAG="$TAG_INPUT" |
| 37 | + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 38 | + TAG="${GITHUB_REF##*/}" |
| 39 | + else |
| 40 | + TAG="$(git rev-parse --short HEAD)" |
| 41 | + fi |
| 42 | + echo "tag=$TAG" | tee -a "$GITHUB_OUTPUT" |
| 43 | +
|
| 44 | + - id: set-matrix |
| 45 | + name: Generate build matrix |
| 46 | + run: | |
| 47 | + TAG='${{ steps.set-tag.outputs.tag }}' |
| 48 | + MATRIX=$(jq -nc --arg tag "$TAG" '{include:[{"arch":"amd64","platform":"linux/amd64","suffix":"-amd64","tag":$tag},{"arch":"arm64","platform":"linux/arm64","suffix":"-arm64","tag":$tag}]}') |
| 49 | + echo "matrix=$MATRIX" | tee -a "$GITHUB_OUTPUT" |
| 50 | +
|
| 51 | + build: |
| 52 | + needs: prepare |
| 53 | + name: Build (${{ matrix.arch }}) |
| 54 | + runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm64' || 'ubuntu-24.04' }} |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: ${{ fromJson(needs.prepare.outputs.matrix) }} |
| 58 | + permissions: |
| 59 | + contents: read |
| 60 | + packages: write |
| 61 | + env: |
| 62 | + REGISTRY: ghcr.io |
| 63 | + IMAGE_NAME: babelcloud/appium |
| 64 | + steps: |
| 65 | + - uses: actions/checkout@v4 |
| 66 | + |
| 67 | + - name: Set up Buildx |
| 68 | + uses: docker/setup-buildx-action@v3 |
| 69 | + |
| 70 | + - name: Login to GitHub Container Registry |
| 71 | + uses: docker/login-action@v3 |
| 72 | + with: |
| 73 | + registry: ${{ env.REGISTRY }} |
| 74 | + username: ${{ secrets.GH_TOKEN_USER }} |
| 75 | + password: ${{ secrets.GH_TOKEN }} |
| 76 | + |
| 77 | + - id: tag-list |
| 78 | + name: Generate architecture-specific tags |
| 79 | + run: | |
| 80 | + FULL_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.tag }}${{ matrix.suffix }}" |
| 81 | + echo "list=$FULL_TAG" | tee -a "$GITHUB_OUTPUT" |
| 82 | +
|
| 83 | + - name: Build & (optional) Push |
| 84 | + uses: docker/build-push-action@v5 |
| 85 | + with: |
| 86 | + context: ./Appium |
| 87 | + file: ./Appium/Dockerfile |
| 88 | + platforms: ${{ matrix.platform }} |
| 89 | + tags: ${{ steps.tag-list.outputs.list }} |
| 90 | + push: true |
| 91 | + provenance: false |
| 92 | + cache-from: type=registry,ref=ghcr.io/babelcloud/appium:buildcache-${{ matrix.arch }} |
| 93 | + cache-to: type=registry,ref=ghcr.io/babelcloud/appium:buildcache-${{ matrix.arch }},mode=max |
| 94 | + |
| 95 | + manifest: |
| 96 | + needs: [prepare, build] |
| 97 | + if: ${{ success() && ((github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true') || startsWith(github.ref, 'refs/tags/')) }} |
| 98 | + runs-on: ubuntu-24.04 |
| 99 | + permissions: |
| 100 | + contents: read |
| 101 | + packages: write |
| 102 | + env: |
| 103 | + REGISTRY: ghcr.io |
| 104 | + IMAGE_NAME: babelcloud/appium |
| 105 | + TAG: ${{ needs.prepare.outputs.tag }} |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v4 |
| 108 | + |
| 109 | + - name: Login to GitHub Container Registry |
| 110 | + uses: docker/login-action@v3 |
| 111 | + with: |
| 112 | + registry: ${{ env.REGISTRY }} |
| 113 | + username: ${{ secrets.GH_TOKEN_USER }} |
| 114 | + password: ${{ secrets.GH_TOKEN }} |
| 115 | + |
| 116 | + - name: Create & Push Manifest |
| 117 | + uses: ./.github/actions/docker-manifest-create-push |
| 118 | + with: |
| 119 | + manifest-list: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} |
| 120 | + manifests: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}-amd64,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}-arm64 |
| 121 | + post-clean: true |
0 commit comments