|
| 1 | +name: ghcr.push exporter |
| 2 | +# This GitHub action builds an image |
| 3 | + |
| 4 | +run-name: Push exporter image to ghcr |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - '*' |
| 9 | +jobs: |
| 10 | + build-and-push-image: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + packages: write |
| 15 | + steps: |
| 16 | + - name: Git checkout |
| 17 | + uses: actions/checkout@v3 |
| 18 | + with: |
| 19 | + fetch-depth: '0' |
| 20 | + - name: Log in to GHCR.io |
| 21 | + |
| 22 | + with: |
| 23 | + registry: ghcr.io |
| 24 | + username: ${{ github.repository_owner }} |
| 25 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + - name: Get image tag |
| 27 | + run: echo "GITHUB_SHA=$GITHUB_SHA" > .env.local |
| 28 | + - name: Set release repo |
| 29 | + run: echo "IMAGE_REPOSITORY=ghcr.io/${{ github.repository_owner }}/mcad-exporter:$GITHUB_SHA" >> .env.local |
| 30 | + - name: Set container builder |
| 31 | + run: echo "CONTAINER_BUILDER=docker" >> .env.local |
| 32 | + - name: Build image |
| 33 | + run: make build-exporter |
| 34 | + - name: Push image |
| 35 | + run: make push-exporter |
| 36 | + - name: Print job result |
| 37 | + run: | |
| 38 | + cat <<EOF >>"${GITHUB_STEP_SUMMARY}" |
| 39 | + - This job's stats is ${{ job.status }}. |
| 40 | + EOF |
| 41 | + tag-version-on-main: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + needs: build-and-push-image |
| 44 | + if: github.ref == 'refs/heads/main' |
| 45 | + permissions: |
| 46 | + contents: read |
| 47 | + packages: write |
| 48 | + steps: |
| 49 | + - name: Git checkout |
| 50 | + uses: actions/checkout@v3 |
| 51 | + with: |
| 52 | + fetch-depth: '0' |
| 53 | + - name: Log in to GHCR.io |
| 54 | + |
| 55 | + with: |
| 56 | + registry: ghcr.io |
| 57 | + username: ${{ github.repository_owner }} |
| 58 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + - name: Get image tag |
| 60 | + run: echo "GITHUB_SHA=$GITHUB_SHA" >> $GITHUB_OUTPUT |
| 61 | + - name: Set origin image tag |
| 62 | + id: origin |
| 63 | + run: echo "IMAGE_REPOSITORY=ghcr.io/${{ github.repository_owner }}/mcad-exporter:$GITHUB_SHA" >> $GITHUB_OUTPUT |
| 64 | + - name: Set version image tag # TODO make version dynamic |
| 65 | + id: target |
| 66 | + run: echo "VERSION_TAG=ghcr.io/${{ github.repository_owner }}/mcad-exporter:v0.1.0" >> $GITHUB_OUTPUT |
| 67 | + - name: Tag and push image |
| 68 | + env: |
| 69 | + ORIGIN_REPO: ${{ steps.origin.outputs.IMAGE_REPOSITORY }} |
| 70 | + TARGET_REPO: ${{ steps.target.outputs.VERSION_TAG }} |
| 71 | + run: | |
| 72 | + docker pull ${{ env.ORIGIN_REPO }} |
| 73 | + docker tag ${{ env.ORIGIN_REPO }} ${{ env.TARGET_REPO }} |
| 74 | + docker push ${{ env.TARGET_REPO }} |
0 commit comments