Skip to content

Commit 049ef2a

Browse files
committed
New ci-cd.yml that pushes container image
1 parent d2d7026 commit 049ef2a

File tree

2 files changed

+61
-25
lines changed

2 files changed

+61
-25
lines changed

.github/workflows/ci-cd.yml

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,73 @@ name: CI/CD
22

33
on:
44
push:
5+
workflow_dispatch:
56

6-
jobs:
7+
concurrency:
8+
group: ${{ github.ref }}
9+
cancel-in-progress: true
710

8-
test_return:
11+
jobs:
12+
version:
913
runs-on: ubuntu-latest
14+
outputs:
15+
semver: ${{ steps.parse.outputs.semver }}
16+
major: ${{ steps.parse.outputs.major }}
17+
minor: ${{ steps.parse.outputs.minor }}
18+
patch: ${{ steps.parse.outputs.patch }}
19+
exists: ${{ steps.parse.outputs.exists }}
1020
steps:
1121
- uses: actions/checkout@v3
12-
- name: 'Integration test: return'
13-
id: output-set
14-
uses: ./
15-
with:
16-
script: |
17-
"return"
18-
- run: |
19-
expected="return"
20-
output="${{steps.output-set.outputs.result}}"
21-
[[ "$output" != "$expected" ]] && echo "::error::❌ Expected '$expected', got '$output'" && exit 1
22-
echo "✅ Test passed, outputs.result: ${{toJSON(steps.output-set.outputs.result)}}"
22+
- uses: pkgxdev/dev@v0
23+
- name: Parse & check version
24+
id: parse
25+
run: |
26+
parse_version_component() {
27+
component=$(echo "$1" | cut -f"$2" -d.)
28+
if [ -z "$component" ]; then
29+
echo "Could not parse version format: $1"
30+
exit 1
31+
fi
32+
echo "$component"
33+
}
34+
check_git_tag_exists() {
35+
git fetch --prune --unshallow --tags
36+
git show-ref --tags v$1 --quiet && echo "true" || echo "false"
37+
}
38+
echo "semver=$VERSION" >> $GITHUB_OUTPUT
39+
echo "major=$(parse_version_component "$VERSION" 1)" >> $GITHUB_OUTPUT
40+
echo "minor=$(parse_version_component "$VERSION" 2)" >> $GITHUB_OUTPUT
41+
echo "patch=$(parse_version_component "$VERSION" 3)" >> $GITHUB_OUTPUT
42+
echo "exists=$(check_git_tag_exists "$VERSION")" >> $GITHUB_OUTPUT
43+
echo GitHub Output: $(cat $GITHUB_OUTPUT)
2344
24-
test_context:
45+
build:
2546
runs-on: ubuntu-latest
2647
steps:
2748
- uses: actions/checkout@v3
28-
- name: 'Integration test: context'
29-
id: output-set
30-
uses: ./
49+
- uses: docker/setup-buildx-action@v3
50+
- uses: docker/metadata-action@v5
51+
id: meta
52+
with:
53+
images: elixir_script:test
54+
- uses: actions/cache@v3
55+
with:
56+
path: /tmp/.buildx-cache
57+
key: ${{ runner.os }}-buildx
58+
restore-keys: |
59+
${{ runner.os }}-buildx-
60+
- name: Build image
61+
uses: docker/build-push-action@v5
62+
with:
63+
context: .
64+
file: .github/Dockerfile
65+
tags: elixir_script:test
66+
outputs: type=docker,dest=/tmp/elixir_script.tar
67+
cache-from: type=local,src=/tmp/.buildx-cache
68+
cache-to: type=local,dest=/tmp/.buildx-cache
69+
labels: ${{ steps.meta.outputs.labels }}
70+
- name: Upload image as artifact
71+
uses: actions/upload-artifact@v3
3172
with:
32-
script: |
33-
Map.keys(context)
34-
- run: |
35-
expected="[__struct__,action,actor,api_url,event_name,graphql_url,job,payload,ref,run_id,run_number,server_url,sha,workflow]"
36-
output="${{steps.output-set.outputs.result}}"
37-
[[ "$output" != "$expected" ]] && echo "::error::❌ Expected '$expected', got '$output'" && exit 1
38-
echo "✅ Test passed, outputs.result: ${{toJSON(steps.output-set.outputs.result)}}"
73+
name: elixir_script
74+
path: /tmp/elixir_script.tar

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ outputs:
1616
description: The stringified return value of the script
1717
runs:
1818
using: docker
19-
image: Dockerfile
19+
image: elixir_script:latest

0 commit comments

Comments
 (0)