generated from goraxe/template
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (140 loc) · 6.18 KB
/
cd.yaml
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
#
name: CD
permissions:
contents: read
# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches: ["main", "master"]
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Trunk Check
uses: trunk-io/trunk-action@v1
semantic-release:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.semantic.outputs.new_release_version }}
new-release-published: ${{ steps.semantic.outputs.new_release_published }}
steps:
- uses: actions/checkout@v4
# you'll need to add an `id` in order to access output variables
- uses: cycjimmy/semantic-release-action@v4
id: semantic
with:
dry_run: true
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-push-image:
needs: [semantic-release, pre-commit]
if: needs.semantic-release.outputs.new-release-published == 'true'
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@327cd5a69de6c009b9ce71bce8395f28e651bf99
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
env:
TAG: v${{ needs.semantic-release.outputs.release-version }}
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.release-version}}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.release-version }}
type=semver,pattern={{major}},value=${{ needs.semantic-release.outputs.release-version }}
type=ref,event=branch
type=ref,event=pr
type=sha
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# create-deployment:
# runs-on: ubuntu-latest
# needs: [semantic-release, build-and-push-image]
# steps:
# - uses: actions/create-github-app-token@v1
# id: app-token
# with:
# app-id: ${{ vars.APP_ID }}
# private-key: ${{ secrets.PRIVATE_KEY }}
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# token: ${{ steps.app-token.outputs.token }}
# - uses: imranismail/setup-kustomize@v2
# - name: run kustomize
# continue-on-error: true
# run: |
# pushd deploy
# kustomize edit set image ghcr.io/ghcr.io/goraxe/portal=ghcr.io/${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.semantic-release.outputs.release-version }}
# git config --local user.name "deployment bot"
# git config --local user.email "github-actions[bot]@users.noreply.github.com"
# git add .
# git commit -m "chore(release): Set image tag to `${{ needs.semantic-release.outputs.release-version }}` [skip ci]"
# git push
# popd
semantic-release-final:
needs:
- build-and-push-image
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.semantic.outputs.release-version }}
new-release-published: ${{ steps.semantic.outputs.new-release-published }}
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
# you'll need to add an `id` in order to access output variables
- uses: cycjimmy/semantic-release-action@v4
id: semantic
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}