-
Notifications
You must be signed in to change notification settings - Fork 75
143 lines (130 loc) · 6.7 KB
/
create-release.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
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
name: Release Extension (v2)
on:
repository_dispatch:
types: [liquibase-release]
workflow_dispatch:
inputs:
liquibaseVersion:
description: "Liquibase Version"
required: true
extensionVersion:
description: "Container Version (Defaults to Liquibase Version)"
required: false
jobs:
setup-update-draft-build:
name: Release ${{ matrix.image.name }} Version ${{ inputs.liquibaseVersion}} ${{ matrix.image.suffix }}
runs-on: ubuntu-latest
strategy:
matrix:
image: [
{dockerfile: Dockerfile, name: liquibase/liquibase, suffix: ""},
{dockerfile: Dockerfile.alpine, name: liquibase/liquibase, suffix: "-alpine"},
]
steps:
- name: Collect Data
id: collect-data
uses: actions/github-script@v6
with:
script: |
const getMinorVersion = (liquibaseVersion) => {
const arr = liquibaseVersion.split(".")
return `${arr[0]}.${arr[1]}`
}
if (context.payload.client_payload) {
const liquibaseVersion = context.payload.client_payload.liquibaseVersion
const minorVersion = getMinorVersion(liquibaseVersion)
core.setOutput("liquibaseVersion", liquibaseVersion);
core.setOutput("extensionVersion", liquibaseVersion);
core.setOutput("minorVersion", minorVersion);
} else if (context.payload.inputs) {
const liquibaseVersion = context.payload.inputs.liquibaseVersion
const minorVersion = getMinorVersion(liquibaseVersion)
core.setOutput("liquibaseVersion", liquibaseVersion);
core.setOutput("extensionVersion", context.payload.inputs.extensionVersion || liquibaseVersion);
core.setOutput("minorVersion", minorVersion);
} else {
core.setFailed('Unknown event type')
}
- run: |
echo "Saw Liquibase version ${{ steps.collect-data.outputs.liquibaseVersion }}"
echo "Saw Extension version ${{ steps.collect-data.outputs.extensionVersion }}"
- uses: actions/checkout@v3
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: "8"
distribution: "adopt"
- name: Configure git user
run: |
git config user.name "liquibot"
git config user.email "[email protected]"
- name: Update Dockerfile and commit changes
run: |
LIQUIBASE_SHA=`curl -LsS https://github.com/liquibase/liquibase/releases/download/v${{ steps.collect-data.outputs.liquibaseVersion }}/liquibase-${{ steps.collect-data.outputs.liquibaseVersion }}.tar.gz | sha256sum | awk '{ print $1 }'`
sed -i 's/^ARG LIQUIBASE_VERSION=.*/ARG LIQUIBASE_VERSION='"${{ steps.collect-data.outputs.liquibaseVersion }}"'/' ${{ github.workspace }}/${{ matrix.image.dockerfile }}
sed -i 's/^ARG LB_SHA256=.*/ARG LB_SHA256='"$LIQUIBASE_SHA"'/' ${{ github.workspace }}/${{ matrix.image.dockerfile }}
git add ${{ matrix.image.dockerfile }}
if git diff-index --cached --quiet HEAD --
then
echo "Nothing new to commit"
else
git commit -m "Liquibase Version Bumped to ${{ steps.collect-data.outputs.extensionVersion }} for ${{ matrix.image.name }} ${{ matrix.image.suffix }}"
git tag -fa -m "Version Bumped to ${{ steps.collect-data.outputs.extensionVersion }}" v${{ steps.collect-data.outputs.extensionVersion }}
git push -f "https://liquibot:[email protected]/$GITHUB_REPOSITORY.git" HEAD:${{ github.ref }} --follow-tags --tags
fi
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
- name: Get release SHA
id: get-release-sha
run: echo "{releaseSha}=$(git rev-parse HEAD)" >> GITHUB_OUPUT
- uses: actions/checkout@v3
- name: Release
uses: softprops/action-gh-release@v1
with:
target_commitish: ${{ steps.get-release-sha.outputs.releaseSha }}
name: v${{ steps.collect-data.outputs.extensionVersion }}
tag_name: v${{ steps.collect-data.outputs.extensionVersion }}
draft: true
body: Support for Liquibase ${{ steps.collect-data.outputs.liquibaseVersion }}.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3 # Checkout the SHA of the updated Dockerfile from the setup step
with:
ref: ${{ steps.get-release-sha.outputs.releaseSha }}
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push Docker Image - Docker Hub
uses: docker/build-push-action@v4
with:
context: .
file: ${{ matrix.image.dockerfile }}
no-cache: true
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ matrix.image.name }}:latest${{ matrix.image.suffix }},${{ matrix.image.name }}:${{ steps.collect-data.outputs.extensionVersion }}${{ matrix.image.suffix }},${{ matrix.image.name }}:${{ steps.collect-data.outputs.minorVersion }}${{ matrix.image.suffix }}
- name: Login to ECR Registry
uses: docker/login-action@v2
env:
AWS_REGION: us-east-1
with:
registry: public.ecr.aws
username: ${{ secrets.PUBLIC_ECR_ACCESS_KEY_ID }}
password: ${{ secrets.PUBLIC_ECR_SECRET_ACCESS_KEY }}
- name: Build and Push Docker Image
env:
ECR_REGISTRY: public.ecr.aws/liquibase/liquibase
uses: docker/build-push-action@v4
with:
context: .
file: ${{ matrix.image.dockerfile }}
no-cache: true
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ matrix.image.name }}:latest${{ matrix.image.suffix }},${{ matrix.image.name }}:${{ steps.collect-data.outputs.extensionVersion }}${{ matrix.image.suffix }},${{ matrix.image.name }}:${{ steps.collect-data.outputs.minorVersion }}${{ matrix.image.suffix }},${{ env.ECR_REGISTRY }}:latest${{ matrix.image.suffix }},${{ env.ECR_REGISTRY }}:${{ steps.collect-data.outputs.extensionVersion }}${{ matrix.image.suffix }},${{ env.ECR_REGISTRY }}:${{ steps.collect-data.outputs.minorVersion }}${{ matrix.image.suffix }}