Publish Docker Image #74
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Docker Image | |
| on: | |
| workflow_run: | |
| workflows: ["Publish Release"] | |
| types: [completed] | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event.workflow_run.head_repository.full_name == github.repository && | |
| github.event.workflow_run.conclusion == 'success' && | |
| startsWith(github.event.workflow_run.head_branch, 'release/v') | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| with: | |
| persist-credentials: false | |
| - name: Extract version | |
| id: version | |
| env: | |
| HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| run: | | |
| VERSION="${HEAD_BRANCH#release/v}" | |
| if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Could not extract a valid version from branch '$HEAD_BRANCH'" >&2 | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Wait for npm package | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| for i in $(seq 1 30); do | |
| if npm view "orval@${VERSION}" version > /dev/null 2>&1; then | |
| exit 0 | |
| fi | |
| echo "orval@${VERSION} not yet on npm, retrying..." | |
| sleep 10 | |
| done | |
| echo "Package never appeared on npm" && exit 1 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| build-args: | | |
| ORVAL_VERSION=${{ steps.version.outputs.version }} | |
| tags: | | |
| ghcr.io/${{ github.repository }}:${{ steps.version.outputs.version }} | |
| ghcr.io/${{ github.repository }}:latest |