Skip to content

Commit aa1852c

Browse files
committed
chore: centralize secure authenticated git push
1 parent b8bddee commit aa1852c

File tree

7 files changed

+39
-10
lines changed

7 files changed

+39
-10
lines changed

.github/scripts/deploy-appstarter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ cp -Rf ${SOURCE}/admin/starter/. ./
3232
# Commit the changes
3333
git add .
3434
git commit -m "Release ${RELEASE}"
35-
git push
35+
bash ${SOURCE}/.github/scripts/secure-git-push https://github.com/codeigniter4/appstarter.git HEAD:master

.github/scripts/deploy-framework

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ cp -Rf ${SOURCE}/admin/starter/tests/. ./tests/
3434
# Commit the changes
3535
git add .
3636
git commit -m "Release ${RELEASE}"
37-
git push
37+
bash ${SOURCE}/.github/scripts/secure-git-push https://github.com/codeigniter4/framework.git HEAD:master

.github/scripts/deploy-userguide

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ touch ${TARGET}/docs/.nojekyll
5858
# Commit the changes
5959
git add .
6060
git commit -m "Release ${RELEASE}"
61-
git push
61+
bash ${SOURCE}/.github/scripts/secure-git-push https://github.com/codeigniter4/userguide.git HEAD:master

.github/scripts/secure-git-push

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ $# -ne 2 ]]; then
6+
echo "Usage: secure-git-push <remote-url> <refspec>" >&2
7+
exit 1
8+
fi
9+
10+
if [[ -z "${PUSH_TOKEN:-}" ]]; then
11+
echo "PUSH_TOKEN is required" >&2
12+
exit 1
13+
fi
14+
15+
REMOTE_URL="$1"
16+
REFSPEC="$2"
17+
AUTH_HEADER="$(printf 'x-access-token:%s' "${PUSH_TOKEN}" | base64 | tr -d '\n')"
18+
19+
echo "::add-mask::${AUTH_HEADER}"
20+
git -c http.https://github.com/.extraheader="AUTHORIZATION: basic ${AUTH_HEADER}" push "${REMOTE_URL}" "${REFSPEC}"
21+
22+
unset AUTH_HEADER PUSH_TOKEN

.github/workflows/deploy-apidocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ jobs:
6868
6969
- name: Deploy to API repo
7070
working-directory: api
71+
env:
72+
PUSH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
7173
run: |
7274
git add .
7375
if ! git diff-index --quiet HEAD; then
7476
git commit -m "Updated API for commit ${GITHUB_SHA}"
75-
git push origin master
77+
bash ${GITHUB_WORKSPACE}/.github/scripts/secure-git-push https://github.com/codeigniter4/api.git HEAD:master
7678
fi

.github/workflows/deploy-distributables.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ jobs:
6767
run: chmod +x ./source/.github/scripts/deploy-framework
6868

6969
- name: Deploy
70+
env:
71+
PUSH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
7072
run: ./source/.github/scripts/deploy-framework ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/framework ${GITHUB_REF##*/}
7173

7274
- name: Release
@@ -119,6 +121,8 @@ jobs:
119121
run: chmod +x ./source/.github/scripts/deploy-appstarter
120122

121123
- name: Deploy
124+
env:
125+
PUSH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
122126
run: ./source/.github/scripts/deploy-appstarter ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/appstarter ${GITHUB_REF##*/}
123127

124128
- name: Release
@@ -181,6 +185,8 @@ jobs:
181185
run: chmod +x ./source/.github/scripts/deploy-userguide
182186

183187
- name: Deploy
188+
env:
189+
PUSH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
184190
run: ./source/.github/scripts/deploy-userguide ${GITHUB_WORKSPACE}/source ${GITHUB_WORKSPACE}/userguide ${GITHUB_REF##*/}
185191

186192
- name: Release

.github/workflows/deploy-userguide-latest.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
build:
2020
name: Deploy to gh-pages
2121
permissions:
22-
# Allow ad-m/github-push-action to push commit to branch gh-pages
22+
# Allow push to branch gh-pages
2323
contents: write
2424
if: (github.repository == 'codeigniter4/CodeIgniter4')
2525
runs-on: ubuntu-24.04
@@ -77,8 +77,7 @@ jobs:
7777
git commit -m "Update User Guide" -a || true
7878
7979
- name: Push changes
80-
uses: ad-m/github-push-action@v1.0.0
81-
with:
82-
branch: gh-pages
83-
directory: gh-pages
84-
github_token: ${{ secrets.ACCESS_TOKEN }}
80+
working-directory: gh-pages
81+
env:
82+
PUSH_TOKEN: ${{ secrets.ACCESS_TOKEN }}
83+
run: bash ${GITHUB_WORKSPACE}/.github/scripts/secure-git-push https://github.com/codeigniter4/CodeIgniter4.git HEAD:gh-pages

0 commit comments

Comments
 (0)