-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (116 loc) · 4.5 KB
/
Copy pathpublish.yml
File metadata and controls
132 lines (116 loc) · 4.5 KB
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
name: App
on:
push:
tags: v*
paths:
- .github/workflows/publish.yml
- build/builder/**
- cmd/**
- internal/**
- go.mod
- go.sum
- .goreleaser.yml
jobs:
prepare:
name: Store the data
runs-on: ubuntu-latest
steps:
- shell: bash
run: |
echo "DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> .env
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> .env
else
echo "VERSION=v${GITHUB_SHA::7}-prerelease" >> .env
fi
- name: Upload the build data
uses: actions/upload-artifact@v1
with:
name: build-data
path: .env
release:
name: Create the release
needs: prepare
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Download the build data
uses: actions/download-artifact@v1
with:
name: build-data
- id: define-variables
name: Define the variables
run: |
export $(cat build-data/.env | xargs)
echo ::set-output name=DATE::$DATE
echo ::set-output name=VERSION::$VERSION
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14.2
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DATE: ${{ steps.define-variables.outputs.DATE }}
docker-image:
name: Publish on the registry
needs: [prepare]
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Download the build data
uses: actions/download-artifact@v1
with:
name: build-data
- id: define-variables
name: Define the variables
run: |
export $(cat build-data/.env | xargs)
echo ::set-output name=DOCKER_PLATFORMS::linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
echo ::set-output name=DOCKER_IMAGE::${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}
echo ::set-output name=DATE::$DATE
echo ::set-output name=COMMIT::${GITHUB_SHA::7}
echo ::set-output name=VERSION::${VERSION#v}
echo ::set-output name=VCS_URL::https://github.com/${GITHUB_REPOSITORY}
- id: buildx
name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
- name: Build an application wthout release
if: success()
run: |
docker buildx build \
--output "type=image,push=false" \
--platform ${{ steps.define-variables.outputs.DOCKER_PLATFORMS }} \
--build-arg "DATE=${{ steps.define-variables.outputs.DATE }}" \
--build-arg "COMMIT=${{ steps.define-variables.outputs.COMMIT }}" \
--build-arg "VERSION=${{ steps.define-variables.outputs.VERSION }}" \
--build-arg "VCS_URL=${{ steps.define-variables.outputs.VCS_URL }}" \
--tag "${{ steps.define-variables.outputs.DOCKER_IMAGE }}:${{ steps.define-variables.outputs.VERSION }}" \
--file ./build/builder/Dockerfile .
- id: docker-login
name: Docker login
if: success()
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login --username "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Build and release an application
if: success()
run: |
docker buildx build --platform ${{ steps.define-variables.outputs.DOCKER_PLATFORMS }} \
--output "type=image,push=true" \
--build-arg "DATE=${{ steps.define-variables.outputs.DATE }}" \
--build-arg "COMMIT=${{ steps.define-variables.outputs.COMMIT }}" \
--build-arg "VERSION=${{ steps.define-variables.outputs.VERSION }}" \
--build-arg "VCS_URL=${{ steps.define-variables.outputs.VCS_URL }}" \
--tag "${{ steps.define-variables.outputs.DOCKER_IMAGE }}:${{ steps.define-variables.outputs.VERSION }}" \
--tag "${{ steps.define-variables.outputs.DOCKER_IMAGE }}:latest" \
--file ./build/builder/Dockerfile .