-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (143 loc) · 5.89 KB
/
main.yml
File metadata and controls
160 lines (143 loc) · 5.89 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
name: Run Sanny Compiler
on:
push:
branches:
- main
workflow_dispatch:
inputs:
script_url:
description: 'URL to the script file'
required: true
type: string
user_id:
description: 'Discord user ID'
required: true
type: string
jobs:
compile:
runs-on: windows-latest
permissions:
contents: write # This gives the workflow permission to write to the repository
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }} # Use the built-in token for authentication
- name: Download script file
run: |
# Download the script file from the provided URL
Write-Host "Downloading script from ${{ github.event.inputs.script_url }}"
Invoke-WebRequest -Uri "${{ github.event.inputs.script_url }}" -OutFile "my.txt"
Get-Content -Path "my.txt" -TotalCount 5
- name: Set up environment and compile
run: |
# Run sanny.exe from the root of the repository to compile my.txt
Write-Host "Compiling script with sanny.exe"
& "$env:GITHUB_WORKSPACE\sanny.exe" -c my.txt
- name: Create artifact archive
if: success()
run: |
# Create a directory for the artifacts
New-Item -Path "compilation_output" -ItemType Directory -Force
# Copy the compiled file and log to the directory
if (Test-Path "my.scm") {
Copy-Item -Path "my.scm" -Destination "compilation_output/"
}
if (Test-Path "compile.log") {
Copy-Item -Path "compile.log" -Destination "compilation_output/"
}
# Create a zip archive
Compress-Archive -Path "compilation_output/*" -DestinationPath "compilation_output.zip" -Force
- name: Upload compiled file
uses: actions/upload-artifact@v4
with:
name: compiled-output
path: my.scm
if-no-files-found: warn
retention-days: 7
- name: Upload compiled.log file
uses: actions/upload-artifact@v4
with:
name: compilation-logs
path: compile.log
if-no-files-found: warn
retention-days: 7
- name: Get artifact URL and set timestamp
id: get_artifact_url
run: |
echo "ARTIFACT_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $env:GITHUB_ENV
echo "TIMESTAMP=$(Get-Date -Format 'o')" >> $env:GITHUB_ENV
# This step is only for internal logging, not for user notification
- name: Log file preparation
if: github.event.inputs.user_id != '' && success()
run: |
# Check if the archive file exists
if (Test-Path "compilation_output.zip") {
Write-Host "Compilation output archive prepared for user ${{ github.event.inputs.user_id }}"
}
else {
Write-Host "Compiled archive file not found!"
echo "SEND_FALLBACK=true" >> $env:GITHUB_ENV
}
- name: Create compilation result file
if: github.event.inputs.user_id != ''
run: |
$result = @{
user_id = "${{ github.event.inputs.user_id }}";
status = "success";
artifact_url = "${{ env.ARTIFACT_URL }}";
timestamp = "${{ env.TIMESTAMP }}";
dm_only = "true"
}
$result | ConvertTo-Json | Set-Content -Path compilation_result.json
- name: Commit compilation result
if: github.event.inputs.user_id != ''
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add compilation_result.json
git commit -m "Add compilation result for user ${{ github.event.inputs.user_id }}"
git push || echo "Failed to push to repository, using alternative method"
# Alternative method: Create a release with the compilation result
- name: Create Release with Compilation Result
if: github.event.inputs.user_id != ''
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: compilation-${{ github.event.inputs.user_id }}-${{ github.run_id }}
release_name: Compilation Result for ${{ github.event.inputs.user_id }}
body: |
Compilation result for user ${{ github.event.inputs.user_id }}
Status: success
Artifact URL: ${{ env.ARTIFACT_URL }}
Timestamp: ${{ env.TIMESTAMP }}
DM Only: true
draft: false
prerelease: false
# Upload the archive to the release
- name: Upload Release Asset
if: github.event.inputs.user_id != '' && success()
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./compilation_output.zip
asset_name: compilation_output.zip
asset_content_type: application/zip
# Clean up temporary files
- name: Clean up temporary files
if: always()
run: |
Write-Host "Cleaning up temporary files..."
if (Test-Path "my.txt") { Remove-Item -Path "my.txt" -Force }
if (Test-Path "my.scm") { Remove-Item -Path "my.scm" -Force }
if (Test-Path "compile.log") { Remove-Item -Path "compile.log" -Force }
if (Test-Path "compilation_output") { Remove-Item -Path "compilation_output" -Recurse -Force }
if (Test-Path "compilation_output.zip") { Remove-Item -Path "compilation_output.zip" -Force }
Write-Host "Temporary files cleaned up"
# Internal logging only - no user notification
- name: Log completion
run: echo "Compilation complete for Discord user ID ${{ github.event.inputs.user_id }} - Results will be sent via DM"