forked from DataDog/dd-trace-java
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (93 loc) · 3.96 KB
/
update-docker-build-image.yaml
File metadata and controls
96 lines (93 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Update Docker Build Image
on:
schedule:
# A day after creating the tag from https://github.com/DataDog/dd-trace-java-docker-build/blob/master/.github/workflows/docker-tag.yml
- cron: "0 0 1 2,5,8,11 *"
workflow_dispatch:
inputs:
tag:
description: "The tag to use for the Docker build image"
required: true
default: "vYY.MM"
jobs:
update-docker-build-image:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for OIDC token federation
steps:
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
id: octo-sts
with:
scope: DataDog/dd-trace-java
policy: self.update-docker-build-image.create-pr
- name: Checkout the repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Define the Docker build image tag to use
id: define-tag
run: |
if [ -n "${{ github.event.inputs.tag }}" ]; then
TAG=${{ github.event.inputs.tag }}
else
CURRENT_MONTH=$(date +%m)
CURRENT_YEAR=$(date +%y)
case $CURRENT_MONTH in
01) TAG_DATE="$(($CURRENT_YEAR - 1)).10" ;;
02|03|04) TAG_DATE="${CURRENT_YEAR}.01" ;;
05|06|07) TAG_DATE="${CURRENT_YEAR}.04" ;;
08|09|10) TAG_DATE="${CURRENT_YEAR}.07" ;;
11|12) TAG_DATE="${CURRENT_YEAR}.10" ;;
esac
TAG="v${TAG_DATE}"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "::notice::Using Docker build image tag: ${TAG}"
- name: Update the Docker build image in GitLab CI config
run: |
sed -i -E 's|(BUILDER_IMAGE_VERSION_PREFIX:)[^#]*([#].*)|\1 "${{ steps.define-tag.outputs.tag }}-" \2|' .gitlab-ci.yml
- name: Check if changes should be committed
id: check-changes
run: |
if [[ -z "$(git status -s)" ]]; then
echo "No changes to commit, exiting."
echo "commit_changes=false" >> "$GITHUB_OUTPUT"
exit 0
else
echo "commit_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Pick a branch name
if: steps.check-changes.outputs.commit_changes == 'true'
id: define-branch
run: echo "branch=ci/update-docker-build-image-$(date +'%Y%m%d')" >> $GITHUB_OUTPUT
- name: Commit changes
if: steps.check-changes.outputs.commit_changes == 'true'
id: create-commit
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "feat(ci): Update Docker build image" .gitlab-ci.yml
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Push changes
uses: DataDog/commit-headless@05d7b7ee023e2c7d01c47832d420c2503cd416f3 # action/v2.0.3
if: steps.check-changes.outputs.commit_changes == 'true'
with:
token: "${{ steps.octo-sts.outputs.token }}"
branch: "${{ steps.define-branch.outputs.branch }}"
# for scheduled runs, sha is the tip of the default branch
# for dispatched runs, sha is the tip of the branch it was dispatched on
head-sha: "${{ github.sha }}"
create-branch: true
command: push
commits: "${{ steps.create-commit.outputs.commit }}"
- name: Create pull request
if: steps.check-changes.outputs.commit_changes == 'true'
env:
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
run: |
gh pr create --title "Update Docker build image" \
--base master \
--head ${{ steps.define-branch.outputs.branch }} \
--label "comp: tooling" \
--label "type: enhancement" \
--label "tag: no release notes" \
--body "This PR updates the Docker build image to ${{ steps.define-tag.outputs.tag }}."