-
Notifications
You must be signed in to change notification settings - Fork 1
66 lines (59 loc) · 2.43 KB
/
last-updated.yaml
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
name: Update last.updated
on:
push:
branches:
- main
- master
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GH_TOKEN: ${{ secrets.TEMPLATES_GITHUB_TOKEN }}
jobs:
update-last-updated-file:
name: "Updates the last.updated file with the current date"
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'platformsh-templates' && github.event.commits[0].author.name != 'GitHub Action' }}
steps:
- name: 'get repo'
id: get-repo
uses: actions/checkout@v3
with:
token: ${{secrets.TEMPLATES_GITHUB_TOKEN }}
- name: 'set git config'
shell: bash
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
- name: 'check for enforce admins'
id: 'check-for-enforce'
shell: bash
run: |
enforceAdmins=$(gh api "/repos/${GITHUB_REPOSITORY}/branches/${DEFAULT_BRANCH}/protection/enforce_admins" --jq '.enabled')
echo "::notice is enforce admins enabled? ${enforceAdmins}"
echo "enforce_admin=${enforceAdmins}" >> $GITHUB_OUTPUT
- name: 'disable enforce admins'
id: 'disable-force-admins'
if: ${{ 'true' == steps.check-for-enforce.outputs.enforce_admin }}
shell: bash
run: |
echo "::notice::Enforce Admins is enabled. Temporarily disabling..."
gh api --method DELETE "/repos/${GITHUB_REPOSITORY}/branches/${DEFAULT_BRANCH}/protection/enforce_admins" --silent \
&& echo "::notice::Enforce admins disabled" \
|| echo "::error::Disabling enforce admin failed"
- name: 'update last.updated'
id: last-updated
shell: bash
run: |
date > ./.platform/last.updated
git add ./.platform/last.updated
git commit -m "auto-updates version, post merge"
git push origin "${DEFAULT_BRANCH}"
- name: "Re-enable enforce admins"
id: re-enable-enforce-admin
if: ${{ 'true' == steps.check-for-enforce.outputs.enforce_admin }}
shell: bash
run: |
gh api --method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${GITHUB_REPOSITORY}/branches/${DEFAULT_BRANCH}/protection/enforce_admins" --silent \
&& echo "::notice::Successfully re-enabled enforce admin" \
|| echo "::error::Re-enabling enforce admins failed."