-
Notifications
You must be signed in to change notification settings - Fork 1.5k
159 lines (145 loc) · 6.84 KB
/
Copy pathimages-branch.yml
File metadata and controls
159 lines (145 loc) · 6.84 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Branch images
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- main
types:
- synchronize
pull_request_review:
types:
- submitted
workflow_dispatch:
inputs:
pr:
required: true
type: number
description: PR number
permissions: {}
jobs:
approval:
# Skip when triggered by pull request events on PR's from forks because the GITHUB_TOKEN on
# those PR's does not have write access, and thus cannot deploy to GHCR.
# Running this workflow against PR's from forks requires manually triggering it via `workflow_dispatch`.
if: ${{ !github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
decision: ${{ steps.decision.outputs.decision }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
persist-credentials: false
- name: Set PR
run: echo "PR=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
if: github.event_name != 'workflow_dispatch'
- name: Set PR when manually triggered (intended for forks)
run: echo "PR=${{ inputs.pr }}" >> $GITHUB_ENV
if: github.event_name == 'workflow_dispatch'
# Skips push-updater-images by setting an output
- name: Check if pull request is approved
id: decision
run: |
# For security, the `gh` call that retrieves the PR approval status *must* also retrieve the commit at the
# tip of the PR to ensure that any subsequent unreviewed commits are not pulled into this action workflow.
DECISION=$(gh pr view ${{ env.PR }} --json reviewDecision,state,commits --jq '"\(.reviewDecision):\(.state):\(.commits | last .oid)"')
echo "decision=$DECISION" >> $GITHUB_OUTPUT
push-updater-images:
runs-on: ubuntu-latest
needs: approval
if: startsWith(needs.approval.outputs.decision, 'APPROVED:OPEN')
strategy:
fail-fast: false
matrix:
suite:
- { name: bazel, ecosystem: bazel }
- { name: bun, ecosystem: bun }
- { name: bundler, ecosystem: bundler }
- { name: cargo, ecosystem: cargo }
- { name: conda, ecosystem: conda }
- { name: composer, ecosystem: composer }
- { name: devcontainers, ecosystem: devcontainers }
- { name: docker_compose, ecosystem: docker-compose }
- { name: docker, ecosystem: docker }
- { name: dotnet_sdk, ecosystem: dotnet-sdk }
- { name: elm, ecosystem: elm }
- { name: git_submodules, ecosystem: gitsubmodule }
- { name: github_actions, ecosystem: github-actions }
- { name: go_modules, ecosystem: gomod }
- { name: gradle, ecosystem: gradle }
- { name: helm, ecosystem: helm }
- { name: hex, ecosystem: mix }
- { name: julia, ecosystem: julia }
- { name: maven, ecosystem: maven }
- { name: mise, ecosystem: mise }
- { name: nix, ecosystem: nix }
- { name: npm_and_yarn, ecosystem: npm }
- { name: nuget, ecosystem: nuget }
- { name: pre_commit, ecosystem: pre-commit }
- { name: pub, ecosystem: pub }
- { name: python, ecosystem: pip }
- { name: rust_toolchain, ecosystem: rust-toolchain }
- { name: swift, ecosystem: swift }
- { name: terraform, ecosystem: terraform }
- { name: opentofu, ecosystem: opentofu }
- { name: uv, ecosystem: uv }
- { name: vcpkg, ecosystem: vcpkg }
permissions:
contents: read
id-token: write
packages: write
env:
DEPENDABOT_UPDATER_VERSION: ${{ github.sha }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
persist-credentials: false
- uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
- name: Prepare tag
run: echo "DEPENDABOT_UPDATER_VERSION=${{ github.sha }}" >> $GITHUB_ENV
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_review'
- name: Prepare tag (forks)
run: |
gh pr checkout ${{ inputs.pr }}
# Ensure the commit we've checked out matches our expected SHA from when we checked the PR's approval status above.
# This is a security measure to prevent any unreviewed commits from getting pulled into this action workflow.
# The format is "APPROVED:OPEN:<PR_COMMIT_SHA>", so compare the end of the string to the current commit.
[[ ${{needs.approval.outputs.decision}} =~ $(git rev-parse HEAD)$ ]]
git fetch origin main
git merge origin/main --ff-only || exit 1
git submodule update --init --recursive
echo "DEPENDABOT_UPDATER_VERSION=$(git rev-parse HEAD)" >> $GITHUB_ENV
if: github.event_name == 'workflow_dispatch'
- uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build ecosystem image
run: script/build ${{ matrix.suite.name }}
- name: Push branch image
run: |
docker tag "ghcr.io/dependabot/dependabot-updater-${{ matrix.suite.ecosystem }}" "ghcr.io/dependabot/dependabot-updater-${{ matrix.suite.ecosystem }}:$DEPENDABOT_UPDATER_VERSION"
docker push "ghcr.io/dependabot/dependabot-updater-${{ matrix.suite.ecosystem }}:$DEPENDABOT_UPDATER_VERSION"
cosign sign --yes $(cosign triangulate --type=digest "ghcr.io/dependabot/dependabot-updater-${{ matrix.suite.ecosystem }}:$DEPENDABOT_UPDATER_VERSION")
- name: Set summary
run: |
echo "updater uploaded with tag \`$DEPENDABOT_UPDATER_VERSION\`" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "ghcr.io/dependabot/dependabot-updater-${{ matrix.suite.ecosystem }}:$DEPENDABOT_UPDATER_VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "deploy for ${{ matrix.suite.ecosystem }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo ".dependabot set-ecosystem-version staging ${{ matrix.suite.ecosystem }} $DEPENDABOT_UPDATER_VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "deploy for all ecosystems" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo ".dependabot set-ecosystem-version staging * $DEPENDABOT_UPDATER_VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY