-
Notifications
You must be signed in to change notification settings - Fork 45
162 lines (149 loc) · 6.2 KB
/
0-welcome.yml
File metadata and controls
162 lines (149 loc) · 6.2 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Step 0, Welcome
on:
workflow_dispatch:
issues:
types: [opened, edited, labeled]
permissions:
contents: write
issues: write
jobs:
get_current_step:
name: Check current step number
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: get_step
run: |
echo "current_step=$(cat ./.github/steps/-step.txt)" >> $GITHUB_OUTPUT
outputs:
current_step: ${{ steps.get_step.outputs.current_step }}
on_quest_selection:
name: Handle quest selection
needs: get_current_step
if: >-
${{ github.event_name == 'issues' &&
(contains(github.event.issue.title, 'Quest') ||
contains(join(github.event.issue.labels.*.name, ' '), 'quest')) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine selected quest
id: determine_quest
run: |
TITLE="${{ github.event.issue.title }}"
if [[ "$TITLE" == *"GenAI prototype"* ]]; then
echo "quest=1" >> $GITHUB_OUTPUT
echo "to_step=1" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"move to Azure"* ]]; then
echo "quest=2" >> $GITHUB_OUTPUT
echo "to_step=2" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"simple chat interface"* ]]; then
echo "quest=3" >> $GITHUB_OUTPUT
echo "to_step=3" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"first AI app with RAG"* ]]; then
echo "quest=4" >> $GITHUB_OUTPUT
echo "to_step=4" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"explore frameworks"* ]]; then
echo "quest=5" >> $GITHUB_OUTPUT
echo "to_step=5" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"build an agent"* ]]; then
echo "quest=6" >> $GITHUB_OUTPUT
echo "to_step=6" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"MCP tools"* ]]; then
echo "quest=7" >> $GITHUB_OUTPUT
echo "to_step=7" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"automate code reviews"* ]]; then
echo "quest=8" >> $GITHUB_OUTPUT
echo "to_step=8" >> $GITHUB_OUTPUT
elif [[ "$TITLE" == *"create templates"* ]]; then
echo "quest=9" >> $GITHUB_OUTPUT
echo "to_step=9" >> $GITHUB_OUTPUT
else
echo "quest=0" >> $GITHUB_OUTPUT
echo "to_step=1" >> $GITHUB_OUTPUT
fi
- name: Update step based on quest selection
if: steps.determine_quest.outputs.quest != '0'
uses: skills/action-update-step@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: 0
to_step: ${{ steps.determine_quest.outputs.to_step }}
- name: Rewrite badge links in README.md to relative paths
run: |
OWNER_REPO="${GITHUB_REPOSITORY}"
# Ensure relative issue links like ](/issues/new?...) remain unchanged
sed -i 's|](https://github.com/'"${OWNER_REPO}"'/issues/new?|](/issues/new?|g' README.md
# Remove any malformed absolute links that include blob/main in the path
sed -i "s#github.com/${OWNER_REPO}/blob/main/issues/new?#/issues/new?#g" README.md
- name: Comment on issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const quest = process.env['DETERMINE_QUEST_OUTPUTS_QUEST'] || '${{ steps.determine_quest.outputs.quest }}';
let message = '';
const readmeUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/README.md`;
if (quest === '0') {
message = "I couldn't determine which quest you selected. Please try again with one of the quests listed in the README.";
} else {
message = `Thanks for selecting this quest! The repository has been updated to guide you through this path. You can close this issue and continue with the instructions in the [README](${readmeUrl}).`;
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
if (quest !== '0') {
github.rest.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
});
}
reset_quest:
name: Handle reset quest
needs: get_current_step
if: >-
${{ github.event_name == 'issues' &&
contains(join(github.event.issue.labels.*.name, ' '), 'reset') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Reset to step 0
uses: skills/action-update-step@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
from_step: ${{ needs.get_current_step.outputs.current_step }}
to_step: 0
- name: Rewrite badge links in README.md to relative paths
run: |
OWNER_REPO="${GITHUB_REPOSITORY}"
# Ensure relative issue links like ](/issues/new?...) remain unchanged
sed -i 's|](https://github.com/'"${OWNER_REPO}"'/issues/new?|](/issues/new?|g' README.md
# Remove any malformed absolute links that include blob/main in the path
sed -i "s#github.com/${OWNER_REPO}/blob/main/issues/new?#/issues/new?#g" README.md
- name: Comment and close issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "Your quest has been reset! You can now select a new quest from the README."
});
github.rest.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
});