This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
185 lines (159 loc) · 6.48 KB
/
push-and-package.yml
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Release Containers
on:
push:
tags:
- 'v*'
jobs:
build-and-push:
name: Build and push images
runs-on: ubuntu-latest
steps:
- name: Free more space
id: free_space
run: |
set -e
# Ensure enough space is available for build
sudo apt-get autoremove -y
sudo apt-get clean -y
sudo rm -rf /usr/share/dotnet
- name: Checkout
id: checkout
uses: actions/checkout@v2
- name: Get tag name
id: get_tag_name
run: echo "::set-output name=tag::$(echo "${{ github.ref }}" | grep -oP 'refs/tags/\K(.+)')"
- name: Azure CLI login
id: az_login
uses: azure/login@v1
with:
creds: ${{ secrets.AZ_ACR_CREDS }}
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Build and push
id: build_and_push
run: |
set -e
# ACR login
ACR_REGISTRY_NAME=$(echo ${{ secrets.REGISTRY }} | grep -oP '(.+)(?=\.azurecr\.io)')
az acr login --name $ACR_REGISTRY_NAME
# Build and push images
yarn install
build/vscdc push --release ${{ steps.get_tag_name.outputs.tag }} \
--github-repo ${{ github.repository }} \
--registry ${{ secrets.REGISTRY }} \
--registry-path ${{ secrets.REGISTRY_BASE_PATH }} \
--stub-registry ${{ secrets.STUB_REGISTRY }} \
--stub-registry-path ${{ secrets.STUB_REGISTRY_BASE_PATH }}
package:
name: Package and release
needs: [build-and-push]
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v2
- name: Get tag name
id: get_tag_name
run: echo "::set-output name=tag::$(echo "${{ github.ref }}" | grep -oP 'refs/tags/\K(.+)')"
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Update Dockerfile common script sources and re-tag
id: update_script_source
run: |
set -e
# Update common script source URLs in all dev containers and and set SHA hash
yarn install
build/vscdc update-script-sources ${{ steps.get_tag_name.outputs.tag }} --github-repo ${{ github.repository }}
# Commit to a new tag specific branch
git config --global user.email "[email protected]"
git config --global user.name "CI"
git fetch --tags --force
git branch ${{ steps.get_tag_name.outputs.tag }}-temp-branch
git add -u
git commit -m 'Automated update of common script sources and hash' || export NO_UPDATES="true"
# Re-tag and push to origin
if [ "${NO_UPDATES}" != "true" ]; then
git fetch --unshallow origin || echo 'Not a shallow clone.'
git tag -d ${{ steps.get_tag_name.outputs.tag }}
git tag ${{ steps.get_tag_name.outputs.tag }}
git push --delete origin ${{ steps.get_tag_name.outputs.tag }}
git push origin ${{ steps.get_tag_name.outputs.tag }}
else
echo "No updates to re-tag."
fi
- name: Package
id: package
run: |
set -e
yarn install
build/vscdc pack --prep-and-package-only \
--release ${{ steps.get_tag_name.outputs.tag }} \
--github-repo ${{ github.repository }} \
--registry ${{ secrets.REGISTRY }} \
--registry-path ${{ secrets.REGISTRY_BASE_PATH }} \
--stub-registry ${{ secrets.STUB_REGISTRY }} \
--stub-registry-path ${{ secrets.STUB_REGISTRY_BASE_PATH }}
# Set an output with the resulting package name for upload
PKG_PREFIX=$(node -p "require('./package.json').name")
echo "::set-output name=package_name::$(ls $PKG_PREFIX-*.tgz)"
- name: Create release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag_name.outputs.tag }}
release_name: ${{ steps.get_tag_name.outputs.tag }}
draft: false
prerelease: false
- name: Upload package as release asset
id: upload_release_asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ steps.package.outputs.package_name }}
asset_name: ${{ steps.package.outputs.package_name }}
asset_content_type: application/gzip
- name: Copy container-features scripts to src folder
id: copy_scripts
run: cp -r ./script-library/*.sh ./script-library/container-features/src
- name: Publish devcontainer container-features
uses: microsoft/publish-dev-container-features-action@main
with:
publish-features: 'true'
path-to-features: './script-library/container-features/src'
publish-definitions: 'true'
path-to-definitions: './containers'
- name: Update release to include features asset
uses: ncipollo/release-action@v1
with:
allowUpdates: true # Lets us upload our own artifact from previous step
artifactErrorsFailBuild: true
artifacts: './devcontainer-*'
token: ${{ secrets.GITHUB_TOKEN }}
image-info:
name: Trigger info extraction
needs: [package]
runs-on: ubuntu-latest
steps:
- name: Get tag name
id: get_tag_name
run: echo "::set-output name=tag::$(echo "${{ github.ref }}" | grep -oP 'refs/tags/\K(.+)')"
- name: Trigger image info file generation
id: image-info
run: |
set -e
echo '(*) Triggering CG manifest and image history generation using workflow_dispatch'
# Use alternate GitHub token due to https://github.community/t5/GitHub-Actions/Triggering-a-new-workflow-from-another-workflow/td-p/31676
curl -X POST \
-H "Authorization: token ${{ secrets.ALTERNATE_GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/version-history.yml/dispatches \
--data "{\"ref\": \"main\", \"inputs\": {\"release\": \"${{ steps.get_tag_name.outputs.tag }}\", \"cg\": \"false\", \"push\": \"true\", \"overwrite\": \"false\"}"