-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
172 lines (159 loc) Β· 6.62 KB
/
action.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
name: 'Docker Deploy Action'
description: >
πͺ A Github Action to deploy pages conveniently
branding:
icon: 'command'
color: 'green'
inputs:
docker_hub_username:
description: Username for Docker Hub
default: ${{ github.actor }}
required: true
docker_hub_password:
description: Docker Hub authentication token
required: true
docker_hub_token:
description: Docker Hub authentication token
required: true
credentials:
description: 'The gcloud credentials'
required: true
image_name:
description: Tag to use for the new image
default: ${{ github.action_repository }}
required: true
dockerfile_path:
description: Path to the dockerfile from which to build the image
required: true
initiate_pauli_sum:
description: Build args
required: false
default: ""
docker_hub_repo_short_description:
description: Short description text for the docker hub repo
required: true
docker_hub_repo_readme_file_path:
description: |
Path of the md file which will be used as the docker hub repo readme
required: true
cache_src:
description: Path for the docker cache source
required: false
default: /tmp/.buildx-cache
cache_dest:
description: Path for the docker cache destinationoh
required: false
default: /tmp/.buildx-cache-new
provider:
description: 'The deploy provider'
required: true
owner:
description: 'The deploy owner'
required: false
token:
description: 'The deploy token'
required: false
repository:
description: 'The deploy repository'
default: ${{ github.repository }}
required: false
outputs:
command:
description: 'The command.outputs'
value: ${{ steps.command.outputs.stdout }}
decays:
description: 'The target repository'
value: ${{ env.PGSERVICEFILE }}
runs:
using: composite
steps:
- name: πͺ Adapt feed mapping
if: runner.os != 'Windows'
shell: bash
run: |
git clone --single-branch -b gh-pages https://github.com/${{ env.TARGET_REPOSITORY }} ${{ github.action_path }}/_site &>/dev/null
mv -f ${{ github.action_path }}/_site/docs ${RUNNER_TEMP}/ && rm -rf ${{ github.action_path }}/_site/*
mv -f ${{ github.workspace }}/_site/* ${{ github.action_path }}/_site/
mv -f ${RUNNER_TEMP}/docs ${{ github.action_path }}/_site/
rm -rf ${{ github.action_path }}/_site/.devcontainer.json ${{ github.action_path }}/_site/Dockerfile
echo 'TARGET_REPOSITORY=${{ env.TARGET_REPOSITORY }}' > ${{ github.action_path }}/_site/.env
echo 'LATEST_COMMIT=${{ env.LATEST_COMMIT }}' >> ${{ github.action_path }}/_site/.env
cat ${{ github.action_path }}/_site/.env && cat ${{ github.action_path }}/Dockerfile
- name: π Initiate Lexer
if: runner.os != 'Windows'
uses: devcontainers/ci@v0.3
id: set-output
with:
push: always
imageTag: id-${{ env.ID }}
skipContainerUserIdUpdate: true
runCmd: ls -alR /home/runner/_site
imageName: ${{ inputs.image_name }}
configFile: ${{ github.action_path }}/.devcontainer.json
env: |
TARGET_REPOSITORY=${{ env.TARGET_REPOSITORY }}
- name: π Variables
if: runner.os != 'Windows'
id: variables
shell: bash
run: |
BASE_NAME=$(basename ${{ inputs.image_name }})
IFS=', '; array=($(curl -L -s 'https://registry.hub.docker.com/v2/repositories/${{ inputs.image_name }}/tags?page_size=1024' | jq -rc '."results"[]["name"]' | yq eval -P | sed "s/ /, /g"))
for ((i=0; i < ${#array[@]}; i++)); do
if [ "${array[$i]}" != "latest" ]; then
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${{ inputs.docker_hub_username }}\", \"password\": \"${{ inputs.docker_hub_password }}\"}" https://hub.docker.com/v2/users/login/ | jq -r .token)
curl -s -i -X DELETE -H "Accept: application/json" -H "Authorization: JWT $HUB_TOKEN" https://hub.docker.com/v2/namespaces/${{ inputs.docker_hub_username }}/repositories/$BASE_NAME/tags/${array[$i]}
echo "deleted: ${{ inputs.image_name }}:${array[$i]}"
fi
done
#Ref: https://gist.github.com/xtrmstep/92aab2d465e348ce1c07ed903ca0dfb8
- id: describe
if: runner.os == 'Windows'
shell: bash
run: |
TF=$(choco install terraform)
ssh-keygen -t rsa -b 4096 -N '' -f $HOME/.ssh/id_rsa -C root && sed -i "1s|^|runner: |" $HOME/.ssh/id_rsa.pub
echo 'instances='$(gcloud compute instances describe grid-${{ env.IMAGE_TAG }} --zone=us-central1-a --format json) >> ${GITHUB_OUTPUT}
gcloud compute instances add-metadata grid-${{ env.IMAGE_TAG }} --zone=us-central1-a --metadata-from-file ssh-keys=$HOME/.ssh/id_rsa.pub > /dev/null
echo 'IP='$(gcloud compute instances describe grid-${{ env.IMAGE_TAG }} --zone=us-central1-a --format='value(networkInterfaces.accessConfigs[0].natIP)') >> ${GITHUB_ENV}
#Ref: https://stackoverflow.com/a/29455821/4058484
- name: πͺ Setup Runner by API
if: runner.os == 'Windows'
id: setup_runner
shell: bash
run: >
curl -s -X POST https://us-central1-feedmapping.cloudfunctions.net/function
-H "Authorization: Bearer $(gcloud auth print-identity-token)" -H "Content-Type: application/json"
-d '${{ steps.describe.outputs.instances }}' | jq '.'
#Ref: https://blog.benoitblanchon.fr/github-action-run-ssh-commands/
- name: Configure SSH
id: 'compute-ssh'
if: runner.os == 'Windows'
shell: bash
run: |
ssh-keyscan -t rsa ${{ env.IP }} >> $HOME/.ssh/known_hosts
chmod 600 $HOME/.ssh/id_rsa
cat << EOL >> $HOME/.ssh/config
Host staging
HostName ${{ env.IP }}
User runner
IdentityFile $HOME/.ssh/id_rsa
StrictHostKeyChecking no
EOL
#Ref: https://github.com/cloudkite-io/google-container-optimized-os-tools
ssh staging 'sudo whoami && sudo ls -al /'
- name: π Set Access Token
if: runner.os == '-Windows'
id: 'o2auth'
uses: 'google-github-actions/auth@v2'
with:
token_format: 'access_token'
credentials_json: ${{ inputs.credentials }}
- name: πͺ Setup Runner by API
if: runner.os == '-Windows'
id: targetLink
shell: bash
run: >
echo 'targetLink='$(curl -s -H "Authorization: Bearer ${{ steps.o2auth.outputs.access_token }}" -H "Content-Type: application/json"
-X POST https://compute.googleapis.com/compute/beta/projects/feedmapping/zones/us-central1-a/instances -d
'{}' | jq '.targetLink') >> ${GITHUB_OUTPUT}