Generate_Docker_Image #299
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: Generate_Docker_Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| repository_dispatch: | |
| types: [trigger-sub-build] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| update_needed: ${{ steps.version_check.outputs.update_needed }} | |
| latest: ${{ steps.version_check.outputs.latest }} | |
| stable_version: ${{ steps.get_stable_version.outputs.stable_version }} | |
| nightly_version: ${{ steps.get_nightly_version.outputs.nightly_version }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| with: | |
| persist-credentials: true | |
| - name: Get Stable Version | |
| id: get_stable_version | |
| env: | |
| GH_PAT: ${{ secrets.GH_PAT }} | |
| run: | | |
| stable=$(curl -s -H "Authorization: Bearer $GH_PAT" https://api.github.com/repos/urnetwork/connect/releases/latest \ | |
| | jq -r '.name') | |
| echo "stable_version=$stable" >> $GITHUB_OUTPUT | |
| - name: Get Nightly Version | |
| id: get_nightly_version | |
| env: | |
| GH_PAT: ${{ secrets.GH_PAT }} | |
| run: | | |
| nightly=$(curl -s -H "Authorization: Bearer $GH_PAT" https://api.github.com/repos/urnetwork/build/releases/latest \ | |
| | jq -r '.name') | |
| echo "nightly_version=$nightly" >> $GITHUB_OUTPUT | |
| - name: Fetch Latest Release Info | |
| id: version_check | |
| env: | |
| GH_PAT: ${{ secrets.GH_PAT }} | |
| run: | | |
| raw=$(curl -s -H "Authorization: Bearer $GH_PAT" https://api.github.com/repos/urnetwork/build/releases/latest \ | |
| | jq -r '.tag_name') | |
| latest=${raw#v} | |
| echo "latest=$latest" >> $GITHUB_OUTPUT | |
| if [[ -f version.txt ]]; then | |
| stored=$(<version.txt) | |
| else | |
| stored="" | |
| fi | |
| echo "stored=$stored" >> $GITHUB_OUTPUT | |
| if [[ "$latest" != "$stored" ]]; then | |
| echo "update_needed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "update_needed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update version.txt | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| run: echo "${{ steps.version_check.outputs.latest }}" > version.txt | |
| - name: Update README.md Build section | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| sed -i \ | |
| "s|^[-*][[:space:]]*UrNetwork_stable[[:space:]]v.*|- UrNetwork_stable ${{ steps.get_stable_version.outputs.stable_version }}|" \ | |
| README.md | |
| sed -i \ | |
| "s|^[-*][[:space:]]*UrNetwork_nightly[[:space:]]v.*|- UrNetwork_nightly ${{ steps.get_nightly_version.outputs.nightly_version }}|" \ | |
| README.md | |
| - name: Commit version.txt back to main | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| git config user.email "${{ secrets.GIT_USER_EMAIL }}" | |
| git config user.name "${{ secrets.GIT_USER_NAME }}" | |
| git add version.txt README.md || true | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Update version.txt to ${{ steps.version_check.outputs.latest }} [skip ci]" | |
| git remote set-url origin https://techroy23:${{ secrets.GH_PAT }}@github.com/techroy23/Docker-UrNetwork.git | |
| git push origin main | |
| else | |
| echo "No changes to commit, skipping git commit/push." | |
| fi | |
| - name: Set up QEMU | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: all | |
| - name: Set Up Docker Buildx | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GHCR_TOKEN }} | |
| - name: Log in to Docker Hub | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: docker.io | |
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
| - name: Build and push image to GHCR & Docker Hub | |
| if: steps.version_check.outputs.update_needed == 'true' || github.event_name == 'workflow_dispatch' | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/docker-urnetwork:${{ steps.version_check.outputs.latest }} | |
| ghcr.io/${{ github.repository_owner }}/docker-urnetwork:latest | |
| docker.io/techroy23/docker-urnetwork:${{ steps.version_check.outputs.latest }} | |
| docker.io/techroy23/docker-urnetwork:latest | |
| secrets: | | |
| id=gh_token,src=${{ secrets.GH_PAT }} |