|
| 1 | +name: Bump ADP Version |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + bump-version: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + id-token: write |
| 14 | + steps: |
| 15 | + - name: Get access token from dd-octo-sts |
| 16 | + uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3 |
| 17 | + id: octo-sts |
| 18 | + with: |
| 19 | + scope: DataDog/saluki |
| 20 | + policy: self.bump-adp-version.create-pr |
| 21 | + |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 |
| 24 | + with: |
| 25 | + token: "${{ steps.octo-sts.outputs.token }}" |
| 26 | + ref: main |
| 27 | + |
| 28 | + - name: Configure Git |
| 29 | + run: | |
| 30 | + git config user.name "github-actions[bot]" |
| 31 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 32 | +
|
| 33 | + - name: Calculate new version |
| 34 | + id: version |
| 35 | + run: | |
| 36 | + CURRENT_VERSION=$(grep -E '^version = "' bin/agent-data-plane/Cargo.toml | head -n 1 | cut -d '"' -f 2) |
| 37 | + echo "Current version: $CURRENT_VERSION" |
| 38 | +
|
| 39 | + MAJOR=$(echo $CURRENT_VERSION | cut -d '.' -f 1) |
| 40 | + MINOR=$(echo $CURRENT_VERSION | cut -d '.' -f 2) |
| 41 | + PATCH=$(echo $CURRENT_VERSION | cut -d '.' -f 3) |
| 42 | + NEW_PATCH=$((PATCH + 1)) |
| 43 | + NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" |
| 44 | +
|
| 45 | + echo "New version: $NEW_VERSION" |
| 46 | + echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 47 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 48 | +
|
| 49 | + - name: Update version in Cargo.toml |
| 50 | + run: | |
| 51 | + CURRENT_VERSION="${{ steps.version.outputs.current_version }}" |
| 52 | + NEW_VERSION="${{ steps.version.outputs.new_version }}" |
| 53 | +
|
| 54 | + sed -i "s/^version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" bin/agent-data-plane/Cargo.toml |
| 55 | +
|
| 56 | + echo "Updated bin/agent-data-plane/Cargo.toml" |
| 57 | +
|
| 58 | + - name: Update Cargo.lock |
| 59 | + run: cargo update -p agent-data-plane --quiet |
| 60 | + |
| 61 | + - name: Create remote branch |
| 62 | + run: | |
| 63 | + BRANCH_NAME=bump-adp-version-${{ steps.version.outputs.new_version }} |
| 64 | + git push origin HEAD:refs/heads/${BRANCH_NAME} |
| 65 | +
|
| 66 | + - name: Commit Changes |
| 67 | + id: commit |
| 68 | + run: | |
| 69 | + git add bin/agent-data-plane/Cargo.toml Cargo.lock |
| 70 | + git commit -m "chore(agent-data-plane): bump version to ${{ steps.version.outputs.new_version }}" |
| 71 | + echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + - name: Sign Commit |
| 74 | + uses: DataDog/commit-headless@5a0f3876e0fbdd3a86b3e008acf4ec562db59eee # v2.0.1 |
| 75 | + with: |
| 76 | + token: "${{ steps.octo-sts.outputs.token }}" |
| 77 | + branch: bump-adp-version-${{ steps.version.outputs.new_version }} |
| 78 | + head-sha: ${{ github.sha }} |
| 79 | + command: push |
| 80 | + commits: "${{ steps.commit.outputs.commit_sha }}" |
| 81 | + |
| 82 | + - name: Create Pull Request |
| 83 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 84 | + with: |
| 85 | + github-token: "${{ steps.octo-sts.outputs.token }}" |
| 86 | + script: | |
| 87 | + const branchName = `bump-adp-version-${{ steps.version.outputs.new_version }}`; |
| 88 | + const prTitle = `chore(agent-data-plane): bump version to ${{ steps.version.outputs.new_version }}`; |
| 89 | + const prBody = `## Summary |
| 90 | +
|
| 91 | + This PR bumps the Agent Data Plane version to ${{ steps.version.outputs.new_version }} for the next development cycle. |
| 92 | +
|
| 93 | + ### Details of change |
| 94 | +
|
| 95 | + - **Previous version:** ${{ steps.version.outputs.current_version }} |
| 96 | + - **New version:** ${{ steps.version.outputs.new_version }} |
| 97 | +
|
| 98 | + _This PR was automatically generated by the [Bump ADP Version](.github/workflows/bump-adp-version.yml) workflow._ |
| 99 | +
|
| 100 | + ## Change Type |
| 101 | +
|
| 102 | + - [ ] Bug fix |
| 103 | + - [ ] New feature |
| 104 | + - [x] Non-functional (chore, refactoring, docs) |
| 105 | + - [ ] Performance`; |
| 106 | + const prLabel = 'ci/bump-adp-version'; |
| 107 | +
|
| 108 | + // Make sure we don't have an open PR for the exact same change. |
| 109 | + const { data: exactPRData } = await github.rest.search.issuesAndPullRequests({ |
| 110 | + q: `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open head:${branchName}` |
| 111 | + }); |
| 112 | +
|
| 113 | + const exactPRs = exactPRData.items; |
| 114 | +
|
| 115 | + if (exactPRs.length > 0) { |
| 116 | + console.log(`Pull request for this version already exists: ${exactPRs[0].html_url}`); |
| 117 | + return; |
| 118 | + } |
| 119 | +
|
| 120 | + // Create the new pull request. |
| 121 | + const updatePR = await github.rest.pulls.create({ |
| 122 | + owner: context.repo.owner, |
| 123 | + repo: context.repo.repo, |
| 124 | + title: prTitle, |
| 125 | + head: branchName, |
| 126 | + base: 'main', |
| 127 | + body: prBody, |
| 128 | + }); |
| 129 | + console.log(`Pull request created: ${updatePR.data.html_url}`); |
| 130 | +
|
| 131 | + // Set the right labels on the PR. |
| 132 | + await github.rest.issues.addLabels({ |
| 133 | + owner: context.repo.owner, |
| 134 | + repo: context.repo.repo, |
| 135 | + issue_number: updatePR.data.number, |
| 136 | + labels: [prLabel, 'automated'] |
| 137 | + }); |
| 138 | +
|
| 139 | + // Look for other open PRs for bumping the ADP version, and close them out so this one takes precedence. |
| 140 | + const { data: labeledPRData } = await github.rest.search.issuesAndPullRequests({ |
| 141 | + q: `repo:${context.repo.owner}/${context.repo.repo} is:pr is:open label:"${prLabel}"` |
| 142 | + }); |
| 143 | +
|
| 144 | + const obsoleteUpdatePRs = labeledPRData.items; |
| 145 | +
|
| 146 | + // Close any existing PRs created from this workflow so that we only have the latest one. |
| 147 | + for (const obsoleteUpdatePR of obsoleteUpdatePRs) { |
| 148 | + // Don't close the PR we just opened. |
| 149 | + if (obsoleteUpdatePR.number == updatePR.data.number) { |
| 150 | + continue; |
| 151 | + } |
| 152 | +
|
| 153 | + console.log(`Closing existing PR: ${obsoleteUpdatePR.html_url}`); |
| 154 | + await github.rest.pulls.update({ |
| 155 | + owner: context.repo.owner, |
| 156 | + repo: context.repo.repo, |
| 157 | + pull_number: obsoleteUpdatePR.number, |
| 158 | + state: 'closed' |
| 159 | + }); |
| 160 | +
|
| 161 | + await github.rest.issues.createComment({ |
| 162 | + owner: context.repo.owner, |
| 163 | + repo: context.repo.repo, |
| 164 | + issue_number: obsoleteUpdatePR.number, |
| 165 | + body: `Closing this pull request as a newer version bump is available: [update PR](https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${updatePR.data.number})` |
| 166 | + }); |
| 167 | + } |
0 commit comments