-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (112 loc) · 3.96 KB
/
release.yml
File metadata and controls
129 lines (112 loc) · 3.96 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
name: Release
run-name: Release for Push on ${{ github.ref_name }} #${{ github.run_number }}
on:
push:
branches:
- main
- next
paths-ignore:
- 'CHANGELOG.md'
env:
ACT: ""
NEW_VERSION: ""
permissions:
contents: read
jobs:
github-release:
name: GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GH_TOKEN_SEMANTIC_RELEASE }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install dependencies
run: npm install
- name: Release
id: semantic_release
if: ${{ !env.ACT }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
OUTPUT=$(npx semantic-release)
echo "$OUTPUT"
NEW_VERSION=$(echo "$OUTPUT" | grep "Published release" | cut -d" " -f9)
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Release (DRY RUN)
id: semantic_release_dry_run
if: ${{ env.ACT }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
DRY_RUN_OUTPUT=$(npx semantic-release --dry-run)
echo "$DRY_RUN_OUTPUT"
NEW_VERSION=$(echo "$DRY_RUN_OUTPUT" | grep "Published release" | cut -d" " -f9)
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
outputs:
new_version: ${{ steps.semantic_release.outputs.new_version }}
new_version_dry_run: ${{ steps.semantic_release_dry_run.outputs.new_version }}
dockerhub-release:
name: Push Image to DockerHub
needs: github-release
if: needs.github-release.outputs.new_version != '' || needs.github-release.outputs.new_version_dry_run != ''
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create Docker Metadata (Tags)
if: ${{ !env.ACT }}
id: meta
uses: docker/metadata-action@v5
with:
images: |
johnnyknighten/example-github-actions-for-container-release
tags: |
type=semver,pattern={{version}},value=${{ needs.github-release.outputs.new_version}}
- name: Create Docker Metadata (Tags) (DRY RUN)
if: ${{ env.ACT }}
id: meta-dry-run
uses: docker/metadata-action@v5
with:
images: |
johnnyknighten/example-github-actions-for-container-release
tags: |
type=semver,pattern={{version}},value=${{ needs.github-release.outputs.new_version_dry_run }}
- name: Push Image to DockerHub
if: ${{ !env.ACT }}
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
- name: Push Image to Docker Hub (DRY RUN)
if: ${{ env.ACT }}
run: |
echo "DRY RUN - Skipping Docker Build and Push"
echo "The Following Images Would Have Been Pushed:"
echo "${{ steps.meta-dry-run.outputs.tags }}"
- name: Update DockerHub description
if: ${{ !env.ACT }}
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: johnnyknighten/example-github-actions-for-container-release
short-description: ${{ github.event.repository.description }}
enable-url-completion: true