|
| 1 | +--- |
| 2 | +name: release |
| 3 | +on: # yamllint disable-line rule:truthy |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +env: |
| 11 | + IMAGE_NAME: ${{ github.repository_owner }}/ldap_sync |
| 12 | + EXCHANGE_PATH: /tmp |
| 13 | + EXCHANGE_FILE: image.tar |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + env: |
| 19 | + BUILD_TAG: ${{ github.job }}.${{ github.run_id }} |
| 20 | + outputs: |
| 21 | + tag: ${{ env.BUILD_TAG }} |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + steps: |
| 25 | + - name: work around github's inability to add a lowercase() function |
| 26 | + run: | |
| 27 | + echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV |
| 28 | + - name: Set up QEMU |
| 29 | + uses: docker/setup-qemu-action@v2 |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v2 |
| 32 | + #- name: Log in to GitHub Container Registry |
| 33 | + # uses: docker/login-action@v2 |
| 34 | + # with: |
| 35 | + # registry: ghcr.io |
| 36 | + # username: ${{ github.repository_owner }} |
| 37 | + # password: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + - name: Build Docker image |
| 39 | + uses: docker/build-push-action@v3 |
| 40 | + with: |
| 41 | + push: false |
| 42 | + # note: because this image is exported, we can only build one platform here |
| 43 | + platforms: linux/amd64 |
| 44 | + tags: ${{ env.LC_IMAGE_NAME }}:${{ env.BUILD_TAG }} |
| 45 | + #tags: ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ env.BUILD_TAG }} |
| 46 | + #cache-from: type=registry,ref=ghcr.io/${{ env.LC_IMAGE_NAME }}:latest |
| 47 | + #cache-to: type=inline |
| 48 | + cache-from: type=gha |
| 49 | + cache-to: type=gha,mode=max |
| 50 | + outputs: type=docker,dest=${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }} |
| 51 | + - name: Upload artifact |
| 52 | + uses: actions/upload-artifact@v3 |
| 53 | + with: |
| 54 | + name: ${{ env.EXCHANGE_FILE }} |
| 55 | + path: ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }} |
| 56 | + |
| 57 | + test_docker_run: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: build |
| 60 | + permissions: |
| 61 | + contents: read |
| 62 | + steps: |
| 63 | + - name: work around github's inability to add a lowercase() function |
| 64 | + run: | |
| 65 | + echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV |
| 66 | + - name: Download artifact |
| 67 | + uses: actions/download-artifact@v3 |
| 68 | + with: |
| 69 | + name: ${{ env.EXCHANGE_FILE }} |
| 70 | + path: ${{ env.EXCHANGE_PATH }} |
| 71 | + - name: Load image |
| 72 | + run: | |
| 73 | + docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }} |
| 74 | + docker image ls -a |
| 75 | + - name: run test |
| 76 | + env: |
| 77 | + SOMEVAR: someval |
| 78 | + run: |
| 79 | + docker run --rm -i $LC_IMAGE_NAME:${{ needs.build.outputs.tag }} /bin/echo "yay" |
| 80 | + |
| 81 | + # TODO: add an actual test of the image :facepalm: |
| 82 | + test_actual_python: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: build |
| 85 | + permissions: |
| 86 | + contents: read |
| 87 | + steps: |
| 88 | + - name: work around github's inability to add a lowercase() function |
| 89 | + run: | |
| 90 | + echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV |
| 91 | + - name: Download artifact |
| 92 | + uses: actions/download-artifact@v3 |
| 93 | + with: |
| 94 | + name: ${{ env.EXCHANGE_FILE }} |
| 95 | + path: ${{ env.EXCHANGE_PATH }} |
| 96 | + - name: Load image |
| 97 | + run: | |
| 98 | + docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }} |
| 99 | + docker image ls -a |
| 100 | + - name: run test |
| 101 | + env: |
| 102 | + SOMEVAR: someval |
| 103 | + run: |
| 104 | + docker run --rm -i $LC_IMAGE_NAME:${{ needs.build.outputs.tag }} /bin/echo "yay" |
| 105 | + |
| 106 | + release: |
| 107 | + runs-on: ubuntu-latest |
| 108 | + needs: |
| 109 | + - build |
| 110 | + - test_docker_run |
| 111 | + - test_actual_python |
| 112 | + if: ${{ github.ref == 'refs/heads/main' && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch' ) }} |
| 113 | + permissions: |
| 114 | + contents: write |
| 115 | + actions: read |
| 116 | + checks: read |
| 117 | + packages: write |
| 118 | + steps: |
| 119 | + - name: work around github's inability to add a lowercase() function |
| 120 | + run: | |
| 121 | + echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> $GITHUB_ENV |
| 122 | +
|
| 123 | + # create the release |
| 124 | + - name: Checkout |
| 125 | + |
| 126 | + with: |
| 127 | + fetch-depth: 0 # need all refs for tag generation |
| 128 | + - name: Auto Increment Semver Action |
| 129 | + uses: MCKanpolat/[email protected] |
| 130 | + id: versioning |
| 131 | + with: |
| 132 | + releaseType: patch |
| 133 | + # this is a read-only action, I think, so either token is ok |
| 134 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + - name: Commit back |
| 136 | + uses: actions-js/push@master |
| 137 | + with: |
| 138 | + # commit back with Github token to avoid retriggering actions |
| 139 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 140 | + message: Release ${{ steps.versioning.outputs.version }} |
| 141 | + branch: main |
| 142 | + - name: Create Github Release |
| 143 | + |
| 144 | + if: steps['versioning']['outputs']['RETURN_STATUS'] == '0' |
| 145 | + with: |
| 146 | + tag: ${{ steps.versioning.outputs.version }} |
| 147 | + name: ${{ steps.versioning.outputs.version }} |
| 148 | + generateReleaseNotes: True |
| 149 | + #body: Version ${{ steps.versioning.outputs.version }} |
| 150 | + draft: false |
| 151 | + prerelease: false |
| 152 | + # # release with PAT to trigger actions on release |
| 153 | + # token: ${{ secrets.ACTION_TOKEN }} |
| 154 | + |
| 155 | + # rebuild the container after (we need to know the tag, but we know |
| 156 | + # this will work because it worked in the job we depend upon) |
| 157 | + - name: Set up QEMU |
| 158 | + uses: docker/setup-qemu-action@v2 |
| 159 | + - name: Set up Docker Buildx |
| 160 | + uses: docker/setup-buildx-action@v2 |
| 161 | + - name: Log in to GitHub Container Registry |
| 162 | + uses: docker/login-action@v2 |
| 163 | + with: |
| 164 | + registry: ghcr.io |
| 165 | + username: ${{ github.repository_owner }} |
| 166 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 167 | +# - name: Login to DockerHub |
| 168 | + |
| 169 | +# with: |
| 170 | +# username: ${{ secrets.DOCKER_USERNAME }} |
| 171 | +# password: ${{ secrets.DOCKER_PASSWORD }} |
| 172 | + - name: Download artifact |
| 173 | + uses: actions/download-artifact@v3 |
| 174 | + with: |
| 175 | + name: ${{ env.EXCHANGE_FILE }} |
| 176 | + path: ${{ env.EXCHANGE_PATH }} |
| 177 | + - name: Load image |
| 178 | + run: | |
| 179 | + docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }} |
| 180 | + docker image ls -a |
| 181 | + - name: Build Docker image |
| 182 | + uses: docker/build-push-action@v3 |
| 183 | + with: |
| 184 | + push: true |
| 185 | + platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 |
| 186 | + tags: | |
| 187 | + ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }} |
| 188 | + ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ steps.versioning.outputs.version }} |
| 189 | + ghcr.io/${{ env.LC_IMAGE_NAME }}:latest |
| 190 | + #tags: | |
| 191 | + # ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }} |
| 192 | + # ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ steps.versioning.outputs.version }} |
| 193 | + # ghcr.io/${{ env.LC_IMAGE_NAME }}:latest |
| 194 | + # ${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }} |
| 195 | + # ${{ env.LC_IMAGE_NAME }}:${{ steps.versioning.outputs.version }} |
| 196 | + # ${{ env.LC_IMAGE_NAME }}:latest |
| 197 | + #cache-from: type=registry,ref=ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }} |
| 198 | + #cache-to: type=inline |
0 commit comments