Repository navigation
84 lines (67 loc) · 2.76 KB
/
Copy pathrelease.yml
File metadata and controls
84 lines (67 loc) · 2.76 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
name: Release
run-name: Release - ${{ github.ref_name }} - ${{ github.run_number }}
on:
workflow_dispatch:
inputs:
mark_as_latest:
description: 'Mark this version as the latest'
required: false
type: boolean
default: true
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Extract version from branch name
id: extract_version
run: |
BRANCH_NAME="${{ github.ref_name }}"
VERSION=$(echo "$BRANCH_NAME" | sed -E 's|^release/([0-9]+\.[0-9]+\.[0-9]+)(-.*)?|\1|')
echo "Branch Name: $BRANCH_NAME"
echo "Extracted Version: $VERSION"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Version should be in the format 'x.x.x'."
exit 1
fi
# Export version to the environment
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Calculate full version with run and attempt
id: calculate_full_version
run: |
VERSION_WITH_RUN="${{ env.VERSION }}-${{ github.run_number }}"
# Export version with run to the environment
echo "VERSION_WITH_RUN=$VERSION_WITH_RUN" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: opensettings
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker image
run: |
docker build -t opensettings/open-settings:${{ env.VERSION_WITH_RUN }} .
- name: Push Docker image to Docker Hub
run: |
docker push opensettings/open-settings:${{ env.VERSION_WITH_RUN }}
if [ "${{ github.event.inputs.mark_as_latest }}" == "true" ]; then
docker tag opensettings/open-settings:${{ env.VERSION_WITH_RUN }} opensettings/open-settings:latest
docker push opensettings/open-settings:latest
fi
- name: Set up GitHub Actions bot user details
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Create and push tag
run: |
TAG_NAME="v${{ env.VERSION_WITH_RUN }}"
git tag $TAG_NAME
git push origin $TAG_NAME
- name: Create GitHub Release
run: gh release create v${{ env.VERSION_WITH_RUN }} --title "Release v${{ env.VERSION_WITH_RUN }}" --notes "This is a release of version v${{ env.VERSION_WITH_RUN }}." --draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}