forked from devcontainers/images
-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (106 loc) · 3.76 KB
/
version-history.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
name: Update version history
on:
workflow_call:
inputs:
release:
description: 'Release branch or tag'
required: true
default: 'main'
type: string
cg:
description: 'Generate cgmanifest.json'
required: true
default: 'false'
type: string
push:
description: 'Update repository with results'
required: true
default: 'true'
type: string
overwrite:
description: 'Overwrite existing files'
required: true
default: 'true'
type: string
jobs:
image_info:
name: Update version history
if: ${{ github.ref == 'refs/heads/main' || github.event.base_ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
environment: documentation
permissions:
contents: write
pull-requests: write
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@v3
- name: Azure CLI login
id: az_login
uses: azure/login@v1
with:
creds: ${{ secrets.AZ_ACR_CREDS }}
- name: Get image info
id: Get_image_info
env:
REGISTRY: ${{ secrets.REGISTRY }}
REGISTRY_BASE_PATH: ${{ secrets.REGISTRY_BASE_PATH }}
STUB_REGISTRY: ${{ secrets.STUB_REGISTRY }}
STUB_REGISTRY_BASE_PATH: ${{ secrets.STUB_REGISTRY_BASE_PATH }}
run: |
set -e
# ACR login
ACR_REGISTRY_NAME=$(echo "$REGISTRY" | grep -oP '(.+)(?=\.azurecr\.io)')
az acr login --name $ACR_REGISTRY_NAME
yarn install
RELEASE_STRING=$(echo "${{ inputs.release }}" | grep -oP 'refs/(heads|tags)/\K(.+)')
OVERWRITE_STRING=$(if [ "${{ inputs.overwrite }}" = "false" ]; then echo '--no-overwrite'; else echo '--overwrite'; fi)
CG_STRING=$(if [ ${{ inputs.cg }} = "false" ]; then echo '--no-cg'; else echo '--cg'; fi)
# Pull images and update cgmanifest.json
build/vscdc info --no-build \
--markdown \
--prune \
--release "$RELEASE_STRING" \
--registry "$REGISTRY" \
--registry-path "$REGISTRY_BASE_PATH" \
--stub-registry "$STUB_REGISTRY" \
--stub-registry-path "$STUB_REGISTRY_BASE_PATH" \
--output-path "$GITHUB_WORKSPACE" \
"$OVERWRITE_STRING" \
"$CG_STRING"
- name: Create PR with updated image information
id: push_image_info
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
set -e
# Configure git and Push updates
git config --global user.email [email protected]
git config --global user.name github-actions
git config pull.rebase false
branch=automated-update-for-image-history-$GITHUB_RUN_ID
git checkout -b $branch
message='Automated update for image history [skip ci]'
# Add / update and commit
git add -A
git commit -m "$message" || export NO_UPDATES=true
# Push (unless disabled for testing)
if [ "$NO_UPDATES" != "true" ] && [ "${{ inputs.push }}" = "true" ]; then
git push origin "$branch"
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${GITHUB_REPOSITORY}/pulls \
-f title="$message" \
-f body="$message" \
-f head="$branch" \
-f base='main'
fi