-
Notifications
You must be signed in to change notification settings - Fork 9
59 lines (56 loc) · 1.75 KB
/
deploy.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
name: Deploy
on:
workflow_call:
inputs:
tag:
description: 'Tag to deploy'
required: true
type: string
environment:
description: 'Environment to deploy to'
required: true
type: string
secrets:
DEPLOYMENT_GITHUB_TOKEN:
description: |
A GitHub token with the following permissions:
contents: write (required; to be able to push to the environment branch)
workflows: write (required; to be able to modify .github/workflows)
required: true
permissions: {}
jobs:
deploy:
name: Deploy ${{ inputs.tag }} to ${{ inputs.environment }}
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.DEPLOYMENT_GITHUB_TOKEN }}
- name: Set up git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Verify tag
env:
TAG: ${{ inputs.tag }}
run: |
git merge-base --is-ancestor $TAG origin/main
if [ $? -ne 0 ]; then
echo "Tag $TAG is not present in the history of main"
exit 1
fi
- name: Checkout environment branch
env:
ENVIRONMENT: ${{ inputs.environment }}
run: git checkout $ENVIRONMENT
- name: Reset environment branch to tag
env:
TAG: ${{ inputs.tag }}
run: git reset --hard $TAG
- name: Force push environment branch
env:
ENVIRONMENT: ${{ inputs.environment }}
run: git push -f origin $ENVIRONMENT