Skip to content

Commit 569fb5f

Browse files
committed
try with post step
1 parent d3500bd commit 569fb5f

File tree

4 files changed

+110
-17
lines changed

4 files changed

+110
-17
lines changed

.github/actions/delete-ghcr-token/action.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ runs:
1010
using: "composite"
1111
steps:
1212
- name: Delete GitHub Container Registry token
13-
shell: bash
14-
run: |
15-
kubectl delete secret ${{ inputs.token-name }}
13+
uses: ./.github/actions/with-post-step
14+
with:
15+
main: |
16+
echo "Main post step action: no action required"
17+
post: |
18+
kubectl delete secret ${{ inputs.token-name }}

.github/actions/delete-k8s-job/action.yml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ runs:
1111
using: "composite"
1212
steps:
1313
- name: Delete Kubernetes job
14-
shell: bash
15-
run: |
16-
# make sure we're deleting all the resources
17-
pods=$(kubectl get pods --selector=batch.kubernetes.io/job-name=${{ inputs.job-name }} -o jsonpath='{.items[*].metadata.name}')
14+
uses: ./.github/actions/with-post-step
15+
with:
16+
main: |
17+
echo "Main post step action: no action required"
18+
post: |
19+
pods=$(kubectl get pods --selector=batch.kubernetes.io/job-name=${{ inputs.job-name }} -o jsonpath='{.items[*].metadata.name}')
1820
19-
for pod in $pods; do
20-
status=$(kubectl get pod "$pod" -o jsonpath='{.status.phase}' || true)
21-
echo "Pod: $pod, status: $status"
22-
if [ "$status" = "Running" ] || [ "$status" = "Pending" ]; then
23-
kubectl delete pod "$pod" --force --grace-period=0 || true
24-
fi
25-
done
26-
27-
# make sure job is deleted
28-
kubectl delete job ${{ inputs.job-name }} --force --grace-period=0 || true
21+
for pod in $pods; do
22+
status=$(kubectl get pod "$pod" -o jsonpath='{.status.phase}' || true)
23+
echo "Pod: $pod, status: $status"
24+
if [ "$status" = "Running" ] || [ "$status" = "Pending" ]; then
25+
kubectl delete pod "$pod" --force --grace-period=0 || true
26+
fi
27+
done
28+
29+
# make sure job is deleted
30+
kubectl delete job ${{ inputs.job-name }} --force --grace-period=0 || true
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ==================================================================================================================== #
2+
# Authors: #
3+
# Patrick Lehmann #
4+
# Unai Martinez-Corral #
5+
# #
6+
# ==================================================================================================================== #
7+
# Copyright 2020-2024 The pyTooling Authors #
8+
# #
9+
# Licensed under the Apache License, Version 2.0 (the "License"); #
10+
# you may not use this file except in compliance with the License. #
11+
# You may obtain a copy of the License at #
12+
# #
13+
# http://www.apache.org/licenses/LICENSE-2.0 #
14+
# #
15+
# Unless required by applicable law or agreed to in writing, software #
16+
# distributed under the License is distributed on an "AS IS" BASIS, #
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
18+
# See the License for the specific language governing permissions and #
19+
# limitations under the License. #
20+
# #
21+
# SPDX-License-Identifier: Apache-2.0 #
22+
# ==================================================================================================================== #
23+
name: With post step
24+
25+
description: 'Generic JS Action to execute a main command and set a command as a post step.'
26+
27+
inputs:
28+
main:
29+
description: 'Main command/script.'
30+
required: true
31+
post:
32+
description: 'Post command/script.'
33+
required: true
34+
key:
35+
description: 'Name of the state variable used to detect the post step.'
36+
required: false
37+
default: POST
38+
39+
runs:
40+
using: 'node20'
41+
main: 'main.js'
42+
post: 'main.js'
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* ================================================================================================================== *
2+
* Authors: *
3+
* Unai Martinez-Corral *
4+
* *
5+
* ================================================================================================================== *
6+
* Copyright 2021-2022 Unai Martinez-Corral <[email protected]> *
7+
* Copyright 2022 Unai Martinez-Corral <[email protected]> *
8+
* *
9+
* Licensed under the Apache License, Version 2.0 (the "License"); *
10+
* you may not use this file except in compliance with the License. *
11+
* You may obtain a copy of the License at *
12+
* *
13+
* http://www.apache.org/licenses/LICENSE-2.0 *
14+
* *
15+
* Unless required by applicable law or agreed to in writing, software *
16+
* distributed under the License is distributed on an "AS IS" BASIS, *
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
18+
* See the License for the specific language governing permissions and *
19+
* limitations under the License. *
20+
* *
21+
* SPDX-License-Identifier: Apache-2.0 *
22+
* ================================================================================================================== *
23+
* *
24+
* Context: *
25+
* * https://github.com/docker/login-action/issues/72 *
26+
* * https://github.com/actions/runner/issues/1478 *
27+
* ================================================================================================================== */
28+
const { spawn } = require("child_process");
29+
const { appendFileSync } = require("fs");
30+
const { EOL } = require("os");
31+
32+
function run(cmd) {
33+
const subprocess = spawn(cmd, { stdio: "inherit", shell: true });
34+
subprocess.on("exit", (exitCode) => {
35+
process.exitCode = exitCode;
36+
});
37+
}
38+
39+
const key = process.env.INPUT_KEY.toUpperCase();
40+
41+
if ( process.env[`STATE_${key}`] !== undefined ) { // Are we in the 'post' step?
42+
run(process.env.INPUT_POST);
43+
} else { // Otherwise, this is the main step
44+
appendFileSync(process.env.GITHUB_STATE, `${key}=true${EOL}`);
45+
run(process.env.INPUT_MAIN);
46+
}

0 commit comments

Comments
 (0)