-
Notifications
You must be signed in to change notification settings - Fork 3
107 lines (93 loc) · 3.45 KB
/
commit-and-push.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
name: add-file-and-commit
on:
workflow_call:
inputs:
authorName:
required: false
type: string
default: carvel-bot
authorEmail:
required: false
type: string
default: [email protected]
repository:
required: true
type: string
branch:
required: false
type: string
default: develop
artifactName:
required: true
type: string
description: Name of the artifact or artifacts that will be added to the git repository
artifactPath:
required: false
type: string
description: Location in the repository where the artifacts will be downloaded to
default: .
secrets:
githubToken:
required: false
githubDeployPrivateKey:
required: false
jobs:
commit-and-push:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
persist-credentials: false
repository: ${{ inputs.repository }}
- name: Download artifacts to be added to the repository
uses: actions/[email protected]
with:
name: ${{ inputs.artifactName }}
path: ${{ inputs.artifactPath }}
- name: Commit & Push changes
env:
AUTHOR_NAME: ${{ inputs.authorName }}
AUTHOR_EMAIL: ${{ inputs.authorEmail }}
REPOSITORY: ${{ inputs.repository }}
BRANCH: ${{ inputs.branch }}
FORCE: false
GITHUB_TOKEN: ${{ secrets.githubToken }}
GITHUB_DEPLOY_PRIVATE_KEY: ${{ secrets.githubDeployPrivateKey }}
run: |
set -e
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
AUTHOR_EMAIL=${AUTHOR_EMAIL:-'github-actions[bot]@users.noreply.github.com'}
AUTHOR_NAME=${AUTHOR_NAME:-'github-actions[bot]'}
MESSAGE=${MESSAGE:-"chore: autopublish ${timestamp}"}
FORCE=${FORCE:-false}
REPOSITORY=${REPOSITORY:-$GITHUB_REPOSITORY}
echo "Push to branch $BRANCH";
[ -z "${BRANCH}" ] && {
echo 'Missing branch';
exit 1;
};
if [ -z "${GITHUB_TOKEN}" ] && [ -z "${GITHUB_DEPLOY_PRIVATE_KEY}" ]; then
echo 'Missing required input "github_token: ${{ secrets.GITHUB_TOKEN }} OR "github_deploy_private_key: ${{ secrets.GITHUB_DEPLOY_PRIVATE_KEY }}".';
exit 1;
fi
if ${FORCE}; then
_FORCE_OPTION='--force'
fi
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
if [ -n "${GITHUB_DEPLOY_PRIVATE_KEY}" ]; then
remote_repo="[email protected]:${REPOSITORY}"
tempkey=`basename $0`
TMP_DEPLOY_PRIV_KEY=`mktemp /tmp/${tempkey}.XXXXXX` || exit 1
echo "${GITHUB_DEPLOY_PRIVATE_KEY}" > $TMP_DEPLOY_PRIV_KEY
eval $(ssh-agent -s)
ssh-add ${TMP_DEPLOY_PRIV_KEY}
fi
git config http.sslVerify true
git config --local user.email "${AUTHOR_EMAIL}"
git config --local user.name "${AUTHOR_NAME}"
git add -A
git commit -m "${MESSAGE}" $_EMPTY || exit 0
git push "${remote_repo}" HEAD:"${BRANCH}" --follow-tags $_FORCE_OPTION;