Skip to content

Commit 5b5a8e2

Browse files
committed
Make deployment.yaml as reusable workflow, for several deploy channels.
1 parent 02fcd81 commit 5b5a8e2

5 files changed

Lines changed: 99 additions & 50 deletions

File tree

.github/actions/build-cuttlefish-cvdremote-debian-package/action.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
name: 'Build debian package cuttlefish-cvdremote'
2+
inputs:
3+
version:
4+
required: false
25
runs:
36
using: "composite"
47
steps:
@@ -12,19 +15,10 @@ runs:
1215
- name: install debuild dependencies
1316
run: apt install -y config-package-dev debhelper-compat devscripts git golang
1417
shell: bash
15-
- name: Setup nightly version
18+
- name: Modify version format
19+
if: inputs.version != ''
1620
run: |
17-
# TODO(b/440196950): Setup condition on this step when we build
18-
# stable/unstable versions here too.
19-
20-
# Modify debian/changelog to build debian package with desired version
21-
# format.
22-
# Stable/Unstable version format : X.Y.Z
23-
# Nightly version format : X.Y.Z~gitYYYYMMDD.<Github SHA 8 digit>
24-
DATE=$(date -u +'%Y%m%d')
25-
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
26-
SUFFIX="~git${DATE}.${SHORT_SHA}"
27-
sed -i "1s/(\([0-9]\+.[0-9]\+.[0-9]\+\))/(\1${SUFFIX})/g" \
21+
sed -i "1s/(\([0-9]\+.[0-9]\+.[0-9]\+\))/(${{ inputs.version }})/g" \
2822
build/debian/cuttlefish_cvdremote/debian/changelog
2923
shell: bash
3024
- name: Build package

.github/actions/deploy-cuttlefish-cloud-orchestrator-docker-image/action.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ name: 'Deploy docker image cuttlefish-cloud-orchestrator'
22
inputs:
33
arch:
44
required: true
5+
version:
6+
required: true
57
runs:
68
using: "composite"
79
steps:
810
- name: Deploy docker image into Artifact Registry
911
run: |
10-
# TODO(b/440196950): Setup condition on this step when we build
11-
# stable/unstable versions here too.
12-
13-
# Stable/Unstable version tag : X.Y.Z
14-
# Nightly version tag : gitYYYYMMDD-<Github SHA 8 digit>
15-
DATE=$(date -u +'%Y%m%d')
16-
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
17-
TAG="git${DATE}-${SHORT_SHA}-${{ inputs.arch }}"
12+
TAG=${{ inputs.version }}-${{ inputs.arch }}
1813
REMOTE_IMAGE_TAG=us-docker.pkg.dev/android-cuttlefish-artifacts/cuttlefish-orchestration/cuttlefish-cloud-orchestrator:${TAG}
1914
2015
docker tag cuttlefish-cloud-orchestrator ${REMOTE_IMAGE_TAG}

.github/workflows/deployment.yaml

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,50 @@
11
name: Deploy artifacts
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
workflow_call:
5+
inputs:
6+
deploy-channel:
7+
required: true
8+
type: string
9+
secrets:
10+
artifact-registry-uploader-json-creds:
11+
required: true
712

813
permissions:
914
contents: read
1015

1116
jobs:
17+
set-variables:
18+
runs-on: ubuntu-24.04
19+
outputs:
20+
version: ${{ steps.define-version.outputs.version }}
21+
steps:
22+
- name: Define version
23+
id: define-version
24+
run: |
25+
TIME=$(date -u +'%Y%m%d%H%M')
26+
# TODO(b/440196950): Setup condition for stable channel.
27+
case "${{ inputs.deploy-channel }}" in
28+
unstable)
29+
# Unstable version format : X.Y-gitYYYYMMDDHHMM-<Github SHA 8 digit>
30+
SEMVER=$(echo ${{ github.ref_name }} | grep -oE '[0-9]+.[0-9]+')
31+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
32+
VERSION="${SEMVER}-git${TIME}-${SHORT_SHA}"
33+
;;
34+
nightly)
35+
# Nightly version format : gitYYYYMMDDHHMM-<Github SHA 8 digit>
36+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
37+
VERSION="git${TIME}-${SHORT_SHA}"
38+
;;
39+
*)
40+
exit 1
41+
;;
42+
esac
43+
echo "version=$VERSION" >> $GITHUB_OUTPUT
44+
echo "Version is $VERSION"
45+
1246
deploy-cuttlefish-cvdremote-amd64-debian-package:
13-
if: github.repository_owner == 'google'
47+
needs: [set-variables]
1448
environment: deployment
1549
runs-on: ubuntu-24.04
1650
container:
@@ -20,19 +54,21 @@ jobs:
2054
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
2155
- name: Build debian package cuttlefish-cvdremote
2256
uses: ./.github/actions/build-cuttlefish-cvdremote-debian-package
57+
with:
58+
version: ${{ needs.set-variables.outputs.version }}
2359
- name: Get exact filename
2460
run: echo "path=$(find . -name cuttlefish-cvdremote_*.deb)" >> $GITHUB_ENV
2561
- name: Authentication on GCP project android-cuttlefish-artifacts
2662
uses: 'google-github-actions/auth@v2'
2763
with:
28-
credentials_json: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
64+
credentials_json: '${{ secrets.artifact-registry-uploader-json-creds }}'
2965
- name: Deploy debian package cuttlefish-cvdremote
3066
uses: ./.github/actions/deploy-cuttlefish-cvdremote-debian-package
3167
with:
3268
path: ${{ env.path }}
3369

3470
deploy-cuttlefish-cvdremote-arm64-debian-package:
35-
if: github.repository_owner == 'google'
71+
needs: [set-variables]
3672
environment: deployment
3773
runs-on: ubuntu-24.04-arm
3874
container:
@@ -42,19 +78,21 @@ jobs:
4278
uses: actions/checkout@a81bbbf8298c0fa03ea29cdc473d45769f953675 # aka v2
4379
- name: Build debian package cuttlefish-cvdremote
4480
uses: ./.github/actions/build-cuttlefish-cvdremote-debian-package
81+
with:
82+
version: ${{ needs.set-variables.outputs.version }}
4583
- name: Get exact filename
4684
run: echo "path=$(find . -name cuttlefish-cvdremote_*.deb)" >> $GITHUB_ENV
4785
- name: Authentication on GCP project android-cuttlefish-artifacts
4886
uses: 'google-github-actions/auth@v2'
4987
with:
50-
credentials_json: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
88+
credentials_json: '${{ secrets.artifact-registry-uploader-json-creds }}'
5189
- name: Deploy debian package cuttlefish-cvdremote
5290
uses: ./.github/actions/deploy-cuttlefish-cvdremote-debian-package
5391
with:
5492
path: ${{ env.path }}
5593

5694
deploy-cuttlefish-cloud-orchestrator-amd64-docker-image:
57-
if: github.repository_owner == 'google'
95+
needs: [set-variables]
5896
environment: deployment
5997
runs-on: ubuntu-24.04
6098
steps:
@@ -65,20 +103,21 @@ jobs:
65103
- name: Authentication on GCP project android-cuttlefish-artifacts
66104
uses: 'google-github-actions/auth@v2'
67105
with:
68-
credentials_json: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
106+
credentials_json: '${{ secrets.artifact-registry-uploader-json-creds }}'
69107
- name: Login to Artifact Registry
70108
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # aka v3.5.0
71109
with:
72110
registry: us-docker.pkg.dev
73111
username: _json_key
74-
password: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
112+
password: '${{ secrets.artifact-registry-uploader-json-creds }}'
75113
- name: Deploy docker image
76114
uses: ./.github/actions/deploy-cuttlefish-cloud-orchestrator-docker-image
77115
with:
78116
arch: amd64
117+
version: ${{ needs.set-variables.outputs.version }}
79118

80119
deploy-cuttlefish-cloud-orchestrator-arm64-docker-image:
81-
if: github.repository_owner == 'google'
120+
needs: [set-variables]
82121
environment: deployment
83122
runs-on: ubuntu-24.04-arm
84123
steps:
@@ -89,21 +128,21 @@ jobs:
89128
- name: Authentication on GCP project android-cuttlefish-artifacts
90129
uses: 'google-github-actions/auth@v2'
91130
with:
92-
credentials_json: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
131+
credentials_json: '${{ secrets.artifact-registry-uploader-json-creds }}'
93132
- name: Login to Artifact Registry
94133
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # aka v3.5.0
95134
with:
96135
registry: us-docker.pkg.dev
97136
username: _json_key
98-
password: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
137+
password: '${{ secrets.artifact-registry-uploader-json-creds }}'
99138
- name: Deploy docker image
100139
uses: ./.github/actions/deploy-cuttlefish-cloud-orchestrator-docker-image
101140
with:
102141
arch: arm64
142+
version: ${{ needs.set-variables.outputs.version }}
103143

104144
deploy-cuttlefish-cloud-orchestrator-docker-manifest:
105-
if: github.repository_owner == 'google'
106-
needs: [deploy-cuttlefish-cloud-orchestrator-amd64-docker-image, deploy-cuttlefish-cloud-orchestrator-arm64-docker-image]
145+
needs: [deploy-cuttlefish-cloud-orchestrator-amd64-docker-image, deploy-cuttlefish-cloud-orchestrator-arm64-docker-image, set-variables]
107146
environment: deployment
108147
runs-on: ubuntu-24.04
109148
steps:
@@ -112,28 +151,19 @@ jobs:
112151
- name: Authentication on GCP project android-cuttlefish-artifacts
113152
uses: 'google-github-actions/auth@v2'
114153
with:
115-
credentials_json: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
154+
credentials_json: '${{ secrets.artifact-registry-uploader-json-creds }}'
116155
- name: Login to Artifact Registry
117156
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # aka v3.5.0
118157
with:
119158
registry: us-docker.pkg.dev
120159
username: _json_key
121-
password: '${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}'
160+
password: '${{ secrets.artifact-registry-uploader-json-creds }}'
122161
- name: Deploy manifests
123162
run: |
124-
# TODO(b/440196950): Setup condition on this step when we build
125-
# stable/unstable versions here too.
126-
127-
# Stable/Unstable version tag : X.Y.Z
128-
# Nightly version tag : gitYYYYMMDD-<Github SHA 8 digit>
129-
DATE=$(date -u +'%Y%m%d')
130-
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
131-
TAG="git${DATE}-${SHORT_SHA}"
132-
IMAGE=us-docker.pkg.dev/android-cuttlefish-artifacts/cuttlefish-orchestration/cuttlefish-cloud-orchestrator
133-
134-
for MANIFEST_TAG in ${TAG} nightly; do
163+
VERSION=${{ needs.set-variables.outputs.version }}
164+
for MANIFEST_TAG in ${VERSION} ${{ inputs.deploy-channel }}; do
135165
docker manifest create ${IMAGE}:${MANIFEST_TAG} \
136-
--amend ${IMAGE}:${TAG}-amd64 \
137-
--amend ${IMAGE}:${TAG}-arm64
166+
--amend ${IMAGE}:${VERSION}-amd64 \
167+
--amend ${IMAGE}:${VERSION}-arm64
138168
docker manifest push ${IMAGE}:${MANIFEST_TAG}
139169
done

.github/workflows/postsubmit.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Postsubmit
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
if: github.repository_owner == 'google'
11+
uses: ./.github/workflows/deployment.yaml
12+
with:
13+
deploy-channel: nightly
14+
secrets:
15+
artifact-registry-uploader-json-creds: ${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Unstable channel
2+
3+
on:
4+
push:
5+
branches:
6+
- 'version-[0-9]+.[0-9]+-dev'
7+
8+
jobs:
9+
deploy:
10+
if: github.repository_owner == 'google'
11+
uses: ./.github/workflows/deployment.yaml
12+
with:
13+
deploy-channel: unstable
14+
secrets:
15+
artifact-registry-uploader-json-creds: ${{ secrets.ARTIFACT_REGISTRY_UPLOADER }}

0 commit comments

Comments
 (0)