-
Notifications
You must be signed in to change notification settings - Fork 9
89 lines (74 loc) · 2.35 KB
/
main.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
---
name: CI
on:
push:
branches:
- master # Push events on master branch
pull_request: # Run tests for any PRs
env:
IMAGE_NAME: aws-cdk-action
jobs:
# Run tests.
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Docker build
run: docker build . --file Dockerfile --tag image
- name: Docker run
run: docker run --entrypoint cdk image --version
lint:
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest
##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v4
################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter/slim@v5
env:
VALIDATE_ALL_CODEBASE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build . --file Dockerfile --tag "$IMAGE_NAME"
- name: Log into GitHub Container Registry
run: >
echo "${{ secrets.GITHUB_TOKEN }}" |
docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/"$IMAGE_NAME"
# Change all uppercase to lowercase
IMAGE_ID=$(echo "$IMAGE_ID" | tr '[:upper:]' '[:lower:]')
SHA="${{ github.sha }}"
# Strip git ref prefix from version
REF=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
echo IMAGE_ID="$IMAGE_ID"
echo SHA="$SHA"
echo REF="$REF"
docker tag "$IMAGE_NAME" "$IMAGE_ID":"$SHA"
docker tag "$IMAGE_NAME" "$IMAGE_ID":"$REF"
docker push "$IMAGE_ID":"$REF"
docker push "$IMAGE_ID":"$SHA"