|
| 1 | +name: Build & publish deck-chores |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: ["*"] |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + ref: |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + secrets: |
| 11 | + DOCKER_AUTH_TOKEN: |
| 12 | + required: true |
| 13 | + PYPI_AUTH_TOKEN: |
| 14 | + required: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + version: |
| 18 | + outputs: |
| 19 | + version: ${{ steps.echo-version.outputs.version }} |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v2 |
| 23 | + with: |
| 24 | + ref: ${{ inputs.ref || github.ref }} |
| 25 | + - uses: actions/setup-python@v2 |
| 26 | + with: |
| 27 | + python-version: 3.9 |
| 28 | + |
| 29 | + |
| 30 | + - id: echo-version |
| 31 | + run: echo "::set-ouput name=version::$(poetry version --short)" |
| 32 | + |
| 33 | + - if: ${{ github.event_name == 'push' }} |
| 34 | + run: "[ ${{ steps.echo-version.outputs.version }} == ${{ github.ref }} ]" |
| 35 | + |
| 36 | + |
| 37 | + cheeseshop: |
| 38 | + name: Build & publish to the cheeseshop |
| 39 | + needs: [version] |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + |
| 43 | + - uses: actions/checkout@v2 |
| 44 | + with: |
| 45 | + ref: ${{ inputs.ref || github.ref }} |
| 46 | + - uses: actions/setup-python@v2 |
| 47 | + with: |
| 48 | + python-version: 3.9 |
| 49 | + |
| 50 | + |
| 51 | + - run: poetry build |
| 52 | + - run: poetry publish --username __token__ --password ${{ secrets.PYPI_AUTH_TOKEN }} |
| 53 | + |
| 54 | + container-image: |
| 55 | + name: Build & push multi-architecture image |
| 56 | + needs: [version] |
| 57 | + env: |
| 58 | + IMAGE_NAME: deck-chores |
| 59 | + DOCKER_IO_USER: funkyfuture |
| 60 | + VERSION: ${{ needs.version.outputs.version }} |
| 61 | + runs-on: ubuntu-latest |
| 62 | + steps: |
| 63 | + |
| 64 | + - uses: redhat-actions/podman-login@v1 |
| 65 | + with: |
| 66 | + registry: ghcr.io |
| 67 | + username: ${{ github.actor }} |
| 68 | + password: ${{ github.token }} |
| 69 | + - uses: redhat-actions/podman-login@v1 |
| 70 | + with: |
| 71 | + registry: docker.io |
| 72 | + username: ${{ env.DOCKER_IO_USER }} |
| 73 | + password: ${{ secrets.DOCKER_AUTH_TOKEN }} |
| 74 | + |
| 75 | + - uses: actions/checkout@v2 |
| 76 | + with: |
| 77 | + ref: ${{ inputs.ref || github.ref }} |
| 78 | + |
| 79 | + - run: > |
| 80 | + echo "PRERELEASE=${{ ( |
| 81 | + contains('a', env.VERSION) || contains('b', env.VERSION) |
| 82 | + || contains('rc', env.VERSION) || contains('pre', env.VERSION) |
| 83 | + ) }}" >> $GITHUB_ENV |
| 84 | + - name: echo version related variables |
| 85 | + run: | |
| 86 | + echo 'VERSION: ${{ env.VERSION }}' |
| 87 | + echo 'PRERELEASE: ${{ env.PRERELEASE }}' |
| 88 | + - id: docker-metadata |
| 89 | + uses: docker/metadata-action@v3 |
| 90 | + with: |
| 91 | + images: ${{ env.IMAGE_NAME }} |
| 92 | + flavor: latest=false |
| 93 | + labels: | |
| 94 | + org.opencontainers.image.documentation=https://deck-chores.readthedocs.org/ |
| 95 | + org.opencontainers.image.url=https://deck-chores.readthedocs.org/ |
| 96 | + tags: | |
| 97 | + type=sha,prefix=src-commit- |
| 98 | + type=pep440,pattern={{version}},value=${{ env.VERSION }} |
| 99 | + type=pep440,pattern={{major}},value=${{ env.VERSION }},enable=${{ env.PRERELEASE == 'false' }} |
| 100 | + type=pep440,pattern={{major}}.{{minor}},value=${{ env.VERSION }},enable=${{ env.PRERELEASE == 'false' }} |
| 101 | + - name: prepare push tag value |
| 102 | + id: push-tags-value |
| 103 | + run: echo "::set-output name=tags::${{ steps.docker-metadata.outputs.tags }}" | tr "\n" " " | sed "s/${{ env.IMAGE_NAME }}://g" |
| 104 | + |
| 105 | + - name: install dependency for multi-platform builds |
| 106 | + run: | |
| 107 | + sudo apt update |
| 108 | + sudo apt install -y qemu-user-static |
| 109 | + - id: build-image |
| 110 | + uses: redhat-actions/buildah-build@v2 |
| 111 | + with: |
| 112 | + containerfiles: | |
| 113 | + ./Dockerfile |
| 114 | + image: ${{ env.IMAGE_NAME }} |
| 115 | + labels: ${{ steps.docker-metadata.outputs.labels }} |
| 116 | + platforms: linux/amd64,linux/arm,linux/arm64 |
| 117 | + tags: ${{ steps.docker-metadata.outputs.tags }} |
| 118 | + |
| 119 | + - name: echo build outputs |
| 120 | + run: | |
| 121 | + echo "Image: ${{ steps.build-image.outputs.image }}" |
| 122 | + echo "Tags: ${{ steps.build-image.outputs.tags }}" |
| 123 | + echo "Tagged Image: ${{ steps.build-image.outputs.image-with-tag }}" |
| 124 | + - name: echo created images |
| 125 | + run: buildah images | grep '${{ env.IMAGE_NAME }}' |
| 126 | + - name: echo image metadata |
| 127 | + run: buildah inspect ${{ steps.build-image.outputs.image-with-tag }} |
| 128 | + |
| 129 | + - name: push to ghcr.io |
| 130 | + uses: redhat-actions/push-to-registry@v2 |
| 131 | + with: |
| 132 | + registry: ghcr.io/${{ github.actor }} |
| 133 | + image: ${{ steps.build-image.outputs.image }} |
| 134 | + tags: ${{ steps.push-tags-value.outputs.tags }} |
| 135 | + |
| 136 | + - name: push to docker.io |
| 137 | + uses: redhat-actions/push-to-registry@v2 |
| 138 | + with: |
| 139 | + registry: docker.io/${{ env.DOCKER_IO_USER }} |
| 140 | + image: ${{ steps.build-image.outputs.image }} |
| 141 | + tags: ${{ steps.push-tags-value.outputs.tags }} |
0 commit comments