|
| 1 | +name: Update Docker Build Image |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # A day after creating the tag from https://github.com/DataDog/dd-trace-java-docker-build/blob/master/.github/workflows/docker-tag.yml |
| 6 | + - cron: '0 0 1 2,5,8,11 *' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: 'The tag to use for the Docker build image' |
| 11 | + required: true |
| 12 | + default: 'vYY.MM-base' |
| 13 | + |
| 14 | +jobs: |
| 15 | + update-docker-build-image: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: write # Required to commit and push changes to a new branch |
| 19 | + pull-requests: write # Required to create a pull request |
| 20 | + steps: |
| 21 | + - name: Checkout the repository |
| 22 | + uses: actions/checkout@v2 |
| 23 | + - name: Download ghcommit CLI |
| 24 | + run: | |
| 25 | + curl https://github.com/planetscale/ghcommit/releases/download/v0.1.48/ghcommit_linux_amd64 -o /usr/local/bin/ghcommit -L |
| 26 | + chmod +x /usr/local/bin/ghcommit |
| 27 | + - name: Pick a branch name |
| 28 | + id: define-branch |
| 29 | + run: echo "branch=ci/update-docker-build-image-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT |
| 30 | + - name: Create branch |
| 31 | + run: | |
| 32 | + git checkout -b ${{ steps.define-branch.outputs.branch }} |
| 33 | + git push -u origin ${{ steps.define-branch.outputs.branch }} --force |
| 34 | + - name: Define the Docker build image tage to use |
| 35 | + id: define-tag |
| 36 | + run: | |
| 37 | + if [ -n "${{ github.event.inputs.tag }}" ]; then |
| 38 | + TAG=${{ github.event.inputs.tag }} |
| 39 | + else |
| 40 | + CURRENT_MONTH=$(date +%m) |
| 41 | + CURRENT_YEAR=$(date +%y) |
| 42 | + case $CURRENT_MONTH in |
| 43 | + 01) TAG_DATE="$(($CURRENT_YEAR - 1)).10" ;; |
| 44 | + 02|03|04) TAG_DATE="${CURRENT_YEAR}.01" ;; |
| 45 | + 05|06|07) TAG_DATE="${CURRENT_YEAR}.04" ;; |
| 46 | + 08|09|10) TAG_DATE="${CURRENT_YEAR}.07" ;; |
| 47 | + 11|12) TAG_DATE="${CURRENT_YEAR}.10" ;; |
| 48 | + esac |
| 49 | + TAG="v${TAG_DATE}-base" |
| 50 | + fi |
| 51 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 52 | + echo "::notice::Using Docker build image tag: ${TAG}" |
| 53 | + - name: Update the Docker build image in CircleCI config |
| 54 | + run: | |
| 55 | + sed -i 's|DOCKER_IMAGE_VERSION=.*|DOCKER_IMAGE_VERSION="${{ steps.define-tag.outputs.tag }}"|' .circleci/render_config.py |
| 56 | + - name: Update the Docker build image in GitLab CI config |
| 57 | + run: | |
| 58 | + sed -i 's|image: ghcr.io/datadog/dd-trace-java-docker-build:.*|image: ghcr.io/datadog/dd-trace-java-docker-build:${{ steps.define-tag.outputs.tag }}|' .gitlab-ci.yml |
| 59 | + - name: Commit and push changes |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 62 | + run: | |
| 63 | + ghcommit --repository ${{ github.repository }} --branch ${{ steps.define-branch.outputs.branch }} --add .circleci/render_config.py --add .gitlab-ci.yml --message "feat(ci): Update Docker build image" |
| 64 | + - name: Create pull request |
| 65 | + env: |
| 66 | + GH_TOKEN: ${{ github.token }} |
| 67 | + run: | |
| 68 | + gh pr create --title "Update Docker build image" \ |
| 69 | + --base master \ |
| 70 | + --head ${{ steps.define-branch.outputs.branch }} \ |
| 71 | + --label "comp: tooling" \ |
| 72 | + --label "type: enhancement" \ |
| 73 | + --label "tag: no release notes" \ |
| 74 | + --body "This PR updates the Docker build image to ${{ steps.define-tag.outputs.tag }}." |
0 commit comments