|
| 1 | +name: Sync Dockerfile image tags to reusable workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + actions: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + sync: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - name: Extract image tags from Dockerfile |
| 19 | + id: extract |
| 20 | + run: | |
| 21 | + doca=$(awk '/ AS BASE_IMAGE_DOCA_FULL_RT_HOST/ {print $2; exit}' Dockerfile) |
| 22 | + go_dev=$(awk '/ AS BASE_IMAGE_GO_DISTROLESS_DEV/ {print $2; exit}' Dockerfile) |
| 23 | + go_base=$(awk '/ AS BASE_IMAGE_GO_DISTROLESS($|\s)/ {print $2; exit}' Dockerfile) |
| 24 | + echo "doca=$doca" >> $GITHUB_OUTPUT |
| 25 | + echo "go_dev=$go_dev" >> $GITHUB_OUTPUT |
| 26 | + echo "go_base=$go_base" >> $GITHUB_OUTPUT |
| 27 | + - name: Update fork-ci-reusable.yml envs if needed |
| 28 | + id: update |
| 29 | + env: |
| 30 | + DOCA: ${{ steps.extract.outputs.doca }} |
| 31 | + GO_DEV: ${{ steps.extract.outputs.go_dev }} |
| 32 | + GO_BASE: ${{ steps.extract.outputs.go_base }} |
| 33 | + run: | |
| 34 | + file=.github/workflows/fork-ci-reusable.yml |
| 35 | + sed -E -i "s#^([[:space:]]*BASE_IMAGE_DOCA_FULL_RT_HOST:)\s*.*#\\1 ${DOCA}#" "$file" |
| 36 | + sed -E -i "s#^([[:space:]]*BASE_IMAGE_GO_DISTROLESS_DEV:)\s*.*#\\1 ${GO_DEV}#" "$file" |
| 37 | + sed -E -i "s#^([[:space:]]*BASE_IMAGE_GO_DISTROLESS:)\s*.*#\\1 ${GO_BASE}#" "$file" |
| 38 | + if git diff --quiet --exit-code -- "$file"; then |
| 39 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 40 | + else |
| 41 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 42 | + fi |
| 43 | + - name: Create Pull Request |
| 44 | + if: steps.update.outputs.changed == 'true' |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }} |
| 47 | + run: | |
| 48 | + git config user.name "nvidia-ci-cd" |
| 49 | + git config user.email "[email protected]" |
| 50 | + BRANCH="chore/sync-dockerfile-images-$(date +%Y%m%d%H%M%S)" |
| 51 | + git checkout -b "$BRANCH" |
| 52 | + git add .github/workflows/fork-ci-reusable.yml |
| 53 | + git commit -m "chore: sync image tags in fork-ci-reusable.yml from Dockerfile" |
| 54 | + git push --set-upstream origin "$BRANCH" |
| 55 | + gh pr create \ |
| 56 | + --title "chore: sync image tags in fork-ci-reusable.yml" \ |
| 57 | + --body $'This PR updates the following envs in `.github/workflows/fork-ci-reusable.yml` based on `Dockerfile`:\n- BASE_IMAGE_DOCA_FULL_RT_HOST\n- BASE_IMAGE_GO_DISTROLESS_DEV\n- BASE_IMAGE_GO_DISTROLESS' \ |
| 58 | + --base main \ |
| 59 | + --head "$BRANCH" |
| 60 | +
|
| 61 | +
|
0 commit comments