-
Notifications
You must be signed in to change notification settings - Fork 4
103 lines (99 loc) · 4.06 KB
/
initialize-request.yml
File metadata and controls
103 lines (99 loc) · 4.06 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Initialize Marketplace Action Request
on:
issues:
types: [opened]
permissions:
issues: write
contents: read
jobs:
parse-issue:
runs-on: self-hosted
outputs:
payload: ${{ steps.issue_body_parser_request.outputs.payload }}
steps:
- name: Get JSON Data out of Issue Request
uses: peter-murray/issue-body-parser-action@v3
id: issue_body_parser_request
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
issue_id: ${{ github.event.issue.number }}
payload_marker: request
fail_on_missing: false
initialize-request:
runs-on: self-hosted
needs: parse-issue
if: needs.parse-issue.outputs.payload != 'NOT_FOUND'
steps:
- name: Lookup the latest release of ${{ fromJson(needs.parse-issue.outputs.payload).owner }}/${{ fromJson(needs.parse-issue.outputs.payload).repo }}
id: get_version
env:
OWNER: ${{ fromJson(needs.parse-issue.outputs.payload).owner }}
REPO: ${{ fromJson(needs.parse-issue.outputs.payload).repo }}
REQUEST_VERSION: ${{ fromJson(needs.parse-issue.outputs.payload).version }}
run: |
if [ $REQUEST_VERSION == 'latest' ]; then
echo "Finding latest release of $OWNER/$REPO..."
export VERSION=`curl https://api.github.com/repos/$OWNER/$REPO/releases/latest | jq -r .name`
if [ "$VERSION" == "null" ]; then
echo "No latest version found for $OWNER/$REPO"
exit 1
fi
else
export VERSION=$REQUEST_VERSION
fi
echo "VERSION: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check out scripts
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
check-latest: true
- name: Install dependencies
run: |
cd .github/scripts
npm install
- name: Create the repo ${{ fromJson(needs.parse-issue.outputs.payload).repo }}_${{ steps.get_version.outputs.version }} on GitHub Enterprise Server
uses: actions/github-script@v7
env:
VERSION: ${{ steps.get_version.outputs.version }}
OWNER: ${{ fromJson(needs.parse-issue.outputs.payload).owner }}
REPO: ${{ fromJson(needs.parse-issue.outputs.payload).repo }}
with:
debug: true
script: |
const { default: initialize } = await import('${{ github.workspace }}/.github/scripts/initialize-request.mjs');
const options = {
token: '${{ secrets.TOKEN }}',
actionsApprovedOrg: '${{ vars.ACTIONS_APPROVED_ORG }}',
baseUrl: '${{ github.api_url }}',
version: process.env.VERSION,
owner: process.env.OWNER,
repo: process.env.REPO
};
await initialize(github, context, options);
- name: Check out requested action repo ${{ fromJson(needs.parse-issue.outputs.payload).owner }}/${{ fromJson(needs.parse-issue.outputs.payload).repo }}_${{ steps.get_version.outputs.version }}
env:
OWNER: ${{ fromJson(needs.parse-issue.outputs.payload).owner }}
REPO: ${{ fromJson(needs.parse-issue.outputs.payload).repo }}
run: |
git clone https://github.com/$OWNER/$REPO requested-action
- name: Push requested action to private repo in $ACTIONS_APPROVED_ORG org on GitHub Enterprise Server
env:
REPO: ${{ fromJson(needs.parse-issue.outputs.payload).repo }}
VERSION: ${{ steps.get_version.outputs.version }}
run: |
cd requested-action
git config user.email '${{ secrets.GITHUB_EMAIL }}'
git config user.name '${{ secrets.GITHUB_USERNAME }}'
if git checkout main; then
git branch -m main-old
fi
git checkout "$VERSION"
git switch -c "$VERSION"-branch
git branch -m main
export GHHOST=${{ github.server_url }}
git remote add origin2 https://${{ secrets.TOKEN }}@${GHHOST#https://}/${{ vars.ACTIONS_APPROVED_ORG }}/"$REPO"_"$VERSION".git
git push -u origin2 main
git push -u origin2 "$VERSION"