-
Notifications
You must be signed in to change notification settings - Fork 2
136 lines (115 loc) · 4.01 KB
/
build.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
name: Bump version, build and release
on:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
tag:
name: Tag and release
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.tag_version.outputs.new_tag }}
new_version: ${{ steps.tag_version.outputs.new_version }}
changelog: ${{ steps.tag_version.outputs.changelog }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: patch
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
build:
name: Build and push
runs-on: ubuntu-latest
needs: tag
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Metadata extraction
id: metadata
uses: docker/metadata-action@v5
with:
# List of Docker images to use as base name for tags
images: |
ghcr.io/${{ github.repository }}
# Generates Docker tags based on the following events/attributes
tags: |
type=raw,value=${{ needs.tag.outputs.new_tag }}
type=raw,value=${{ needs.tag.outputs.new_version }}
type=sha
latest
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
deployment:
name: Update deployment
runs-on: ubuntu-latest
needs: [build, tag]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-deployment
cancel-in-progress: true
steps:
- name: Check if deployment PAT is set
id: deployment_check
run: |
if [ -z "${{ secrets.DEPLOYMENT_PAT }}" ]; then
echo "DEPLOYMENT_PAT is not set. Skipping deployment."
echo "deployment_enabled=false" >> $GITHUB_OUTPUT
exit 0
else
echo "deployment_enabled=true" >> $GITHUB_OUTPUT
echo "deployment_enabled=true" >> $GITHUB_OUTPUT
fi
- name: Update deployment
uses: actions/github-script@v7
if: steps.deployment_check.outputs.deployment_enabled == 'true'
with:
github-token: ${{ secrets.DEPLOYMENT_PAT }}
script: |
const owner = '${{ secrets.DEPLOYMENT_OWNER }}'
const repo = '${{ secrets.DEPLOYMENT_REPO }}'
const workflow_id = '${{ secrets.DEPLOYMENT_WORKFLOW }}'
const ref = 'main'
const deployment_name = '${{ secrets.DEPLOYMENT_NAME }}'
const version = '${{ needs.tag.outputs.new_version }}'
if (!owner || !repo || !workflow_id || !deployment_name || !version) {
core.setFailed('Missing required inputs')
return
}
// Trigger the workflow dispatch using Octokit API (from github object)
await github.rest.actions.createWorkflowDispatch({
owner: owner,
repo: repo,
workflow_id: workflow_id,
ref: ref,
inputs: {
version: version,
deployment: deployment_name,
}
});
console.log('Workflow dispatch triggered successfully.');