1+ name : ci
2+
3+ on :
4+ workflow_dispatch :
5+ push :
6+ branches-ignore :
7+ - " preview/**"
8+ paths-ignore :
9+ # - .github
10+ # - .scripts
11+ # - .charts
12+ - LICENSE
13+ - README.md
14+ pull_request :
15+ branches : [main]
16+ types : [opened, synchronize, reopened]
17+
18+ env :
19+ IMAGE_NAME : multi-arch-container-rust
20+
21+ jobs :
22+ build_app :
23+ runs-on : ubuntu-latest
24+ outputs :
25+ SemVer : ${{ steps.gitversion.outputs.SemVer }}
26+ FullSemVer : ${{ steps.gitversion.outputs.FullSemVer }}
27+
28+ steps :
29+ - uses : actions/checkout@v3
30+ with :
31+ fetch-depth : 0
32+
33+ - name : gitversion
34+ shell : pwsh
35+ id : gitversion
36+ run : |
37+ dotnet tool update -g GitVersion.Tool
38+ $GitVersion = dotnet-gitversion ${{ github.workspace }} /nofetch | ConvertFrom-Json
39+ Write-Host "SemVer=$($GitVersion.SemVer)"
40+ echo "SemVer=$($GitVersion.SemVer)" >> $env:GITHUB_OUTPUT
41+ Write-Host "FullSemVer=$($GitVersion.FullSemVer)"
42+ echo "FullSemVer=$($GitVersion.FullSemVer)" >> $env:GITHUB_OUTPUT
43+
44+ - name : cargo fetch
45+ run : cargo fetch
46+
47+ - name : cargo build
48+ run : cargo build --release
49+
50+ # TODO: could run cargo test here, etc...
51+
52+ build_image :
53+ if : false # debug disable
54+ runs-on : ubuntu-latest
55+ needs : build_app
56+
57+ # https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/
58+ # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
59+ permissions :
60+ packages : write # for pushing container image
61+
62+ env :
63+ REGISTRY : ghcr.io
64+ # REPOSITORY: Note: set dynamically, i.e. github.repository_owner+IMAGE_NAME
65+ GIT_REPO : ${{ github.repository }}
66+ GIT_TAG : ${{ needs.build_app.outputs.SemVer }}
67+ GIT_BRANCH : ${{ github.ref }}
68+ GIT_COMMIT : ${{ github.sha }}
69+
70+ steps :
71+
72+ - uses : actions/checkout@v3
73+ with :
74+ fetch-depth : 0
75+
76+ - name : set vars (1 of 2)
77+ run : echo "REPOSITORY=${{ github.repository_owner }}/$IMAGE_NAME" >> $GITHUB_ENV
78+
79+ - name : set vars (2 of 2)
80+ if : github.ref != 'refs/heads/main' # non-default branch has a more verbose SemVer which we overwrite
81+ run : echo "GIT_TAG=dev" >> $GITHUB_ENV
82+
83+ - name : image:base
84+ run : docker build --platform linux/amd64 -t image:base . --target base
85+ if : false # debug
86+
87+ - name : image:dependencies
88+ run : docker build --platform linux/amd64 -t image:dependencies . --target dependencies
89+ if : false # debug
90+
91+ - name : image:source
92+ run : docker build --platform linux/amd64 -t image:source . --target source
93+ if : false # debug
94+
95+ - name : image:build
96+ run : docker build --platform linux/amd64 -t image:build . --target build
97+ if : false # debug
98+
99+ - name : image:final
100+ run : docker build --platform linux/amd64 -t image:final . --target final
101+ if : false # debug
102+
103+ - name : cargo version
104+ run : cargo version
105+ if : false # debug
106+
107+ - name : cargo fmt
108+ run : docker run --rm --name fmt image:source cargo fmt --all --check
109+ # if: always()
110+ if : false # debug
111+
112+ - name : cargo clippy
113+ run : docker run --rm --name clippy image:source cargo clippy -- -D warnings
114+ # if: always()
115+ if : false # debug
116+
117+ # - name: cargo test
118+ # run: docker run --rm --name clippy image:build cargo test
119+ # if: always()
120+
121+ - name : docker login ${{ env.REGISTRY }}
122+ run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
123+
124+ - name : docker buildx build
125+ run : |
126+ docker buildx create --name multiarchtest --use
127+ docker buildx build \
128+ -t $REGISTRY/$REPOSITORY:$GIT_TAG \
129+ -t $REGISTRY/$REPOSITORY:latest \
130+ --label "GITHUB_RUN_ID=${{ github.run_id }}" \
131+ --label "IMAGE_NAME=$IMAGE_NAME" \
132+ --build-arg GIT_REPO=$GIT_REPO \
133+ --build-arg GIT_TAG=$GIT_TAG \
134+ --build-arg GIT_BRANCH=$GIT_BRANCH \
135+ --build-arg GIT_COMMIT=$GIT_COMMIT \
136+ --build-arg GITHUB_WORKFLOW=${{ github.workflow }} \
137+ --build-arg GITHUB_RUN_ID=${{ github.run_id }} \
138+ --build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \
139+ --platform linux/amd64,linux/arm64,linux/arm/v7 \
140+ --pull \
141+ --push \
142+ .
0 commit comments