Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
setup-python/src/install-python.ts at main · solveforceapp/setup-python · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
solveforceapp
setup-python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
setup-python
/
src
/
install-python.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
164 lines (152 loc) · 4.88 KB
main
Breadcrumbs
setup-python
/
src
/
install-python.ts
Copy path
Top
File metadata and controls
Code
Blame
164 lines (152 loc) · 4.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
163
164
import
*
as
path
from
'path'
;
import
*
as
core
from
'@actions/core'
;
import
*
as
tc
from
'@actions/tool-cache'
;
import
*
as
exec
from
'@actions/exec'
;
import
*
as
httpm
from
'@actions/http-client'
;
import
{
ExecOptions
}
from
'@actions/exec/lib/interfaces'
;
import
{
IS_WINDOWS
,
IS_LINUX
,
getDownloadFileName
}
from
'./utils'
;
import
{
IToolRelease
}
from
'@actions/tool-cache'
;
const
TOKEN
=
core
.
getInput
(
'token'
)
;
const
AUTH
=
!
TOKEN
?
undefined
:
`token
${
TOKEN
}
`
;
const
MANIFEST_REPO_OWNER
=
'actions'
;
const
MANIFEST_REPO_NAME
=
'python-versions'
;
const
MANIFEST_REPO_BRANCH
=
'main'
;
export
const
MANIFEST_URL
=
`https://raw.githubusercontent.com/
${
MANIFEST_REPO_OWNER
}
/
${
MANIFEST_REPO_NAME
}
/
${
MANIFEST_REPO_BRANCH
}
/versions-manifest.json`
;
export
async
function
findReleaseFromManifest
(
semanticVersionSpec
:
string
,
architecture
:
string
,
manifest
:
tc
.
IToolRelease
[
]
|
null
)
:
Promise
<
tc
.
IToolRelease
|
undefined
>
{
if
(
!
manifest
)
{
manifest
=
await
getManifest
(
)
;
}
const
foundRelease
=
await
tc
.
findFromManifest
(
semanticVersionSpec
,
false
,
manifest
,
architecture
)
;
return
foundRelease
;
}
function
isIToolRelease
(
obj
:
any
)
:
obj
is
IToolRelease
{
return
(
typeof
obj
===
'object'
&&
obj
!==
null
&&
typeof
obj
.
version
===
'string'
&&
typeof
obj
.
stable
===
'boolean'
&&
Array
.
isArray
(
obj
.
files
)
&&
obj
.
files
.
every
(
(
file
:
any
)
=>
typeof
file
.
filename
===
'string'
&&
typeof
file
.
platform
===
'string'
&&
typeof
file
.
arch
===
'string'
&&
typeof
file
.
download_url
===
'string'
)
)
;
}
export
async
function
getManifest
(
)
:
Promise
<
tc
.
IToolRelease
[
]
>
{
try
{
const
repoManifest
=
await
getManifestFromRepo
(
)
;
if
(
Array
.
isArray
(
repoManifest
)
&&
repoManifest
.
length
&&
repoManifest
.
every
(
isIToolRelease
)
)
{
return
repoManifest
;
}
throw
new
Error
(
'The repository manifest is invalid or does not include any valid tool release (IToolRelease) entries.'
)
;
}
catch
(
err
)
{
core
.
debug
(
'Fetching the manifest via the API failed.'
)
;
if
(
err
instanceof
Error
)
{
core
.
debug
(
err
.
message
)
;
}
else
{
core
.
error
(
'An unexpected error occurred while fetching the manifest.'
)
;
}
}
return
await
getManifestFromURL
(
)
;
}
export
function
getManifestFromRepo
(
)
:
Promise
<
tc
.
IToolRelease
[
]
>
{
core
.
debug
(
`Getting manifest from
${
MANIFEST_REPO_OWNER
}
/
${
MANIFEST_REPO_NAME
}
@
${
MANIFEST_REPO_BRANCH
}
`
)
;
return
tc
.
getManifestFromRepo
(
MANIFEST_REPO_OWNER
,
MANIFEST_REPO_NAME
,
AUTH
,
MANIFEST_REPO_BRANCH
)
;
}
export
async
function
getManifestFromURL
(
)
:
Promise
<
tc
.
IToolRelease
[
]
>
{
core
.
debug
(
'Falling back to fetching the manifest using raw URL.'
)
;
const
http
:
httpm
.
HttpClient
=
new
httpm
.
HttpClient
(
'tool-cache'
)
;
const
response
=
await
http
.
getJson
<
tc
.
IToolRelease
[
]
>
(
MANIFEST_URL
)
;
if
(
!
response
.
result
)
{
throw
new
Error
(
`Unable to get manifest from
${
MANIFEST_URL
}
`
)
;
}
return
response
.
result
;
}
async
function
installPython
(
workingDirectory
:
string
)
{
const
options
:
ExecOptions
=
{
cwd
:
workingDirectory
,
env
:
{
...
process
.
env
,
...
(
IS_LINUX
&&
{
LD_LIBRARY_PATH
:
path
.
join
(
workingDirectory
,
'lib'
)
}
)
}
,
silent
:
true
,
listeners
:
{
stdout
:
(
data
:
Buffer
)
=>
{
core
.
info
(
data
.
toString
(
)
.
trim
(
)
)
;
}
,
stderr
:
(
data
:
Buffer
)
=>
{
core
.
error
(
data
.
toString
(
)
.
trim
(
)
)
;
}
}
}
;
if
(
IS_WINDOWS
)
{
await
exec
.
exec
(
'powershell'
,
[
'./setup.ps1'
]
,
options
)
;
}
else
{
await
exec
.
exec
(
'bash'
,
[
'./setup.sh'
]
,
options
)
;
}
}
export
async
function
installCpythonFromRelease
(
release
:
tc
.
IToolRelease
)
{
if
(
!
release
.
files
||
release
.
files
.
length
===
0
)
{
throw
new
Error
(
'No files found in the release to download.'
)
;
}
const
downloadUrl
=
release
.
files
[
0
]
.
download_url
;
core
.
info
(
`Download from "
${
downloadUrl
}
"`
)
;
let
pythonPath
=
''
;
try
{
const
fileName
=
getDownloadFileName
(
downloadUrl
)
;
pythonPath
=
await
tc
.
downloadTool
(
downloadUrl
,
fileName
,
AUTH
)
;
core
.
info
(
'Extract downloaded archive'
)
;
let
pythonExtractedFolder
;
if
(
IS_WINDOWS
)
{
pythonExtractedFolder
=
await
tc
.
extractZip
(
pythonPath
)
;
}
else
{
pythonExtractedFolder
=
await
tc
.
extractTar
(
pythonPath
)
;
}
core
.
info
(
'Execute installation script'
)
;
await
installPython
(
pythonExtractedFolder
)
;
}
catch
(
err
)
{
if
(
err
instanceof
tc
.
HTTPError
)
{
// Rate limit?
if
(
err
.
httpStatusCode
===
403
)
{
core
.
error
(
`Received HTTP status code 403. This indicates a permission issue or restricted access.`
)
;
}
else
if
(
err
.
httpStatusCode
===
429
)
{
core
.
info
(
`Received HTTP status code 429. This usually indicates the rate limit has been exceeded`
)
;
}
else
{
core
.
info
(
err
.
message
)
;
}
if
(
err
.
stack
)
{
core
.
debug
(
err
.
stack
)
;
}
}
throw
err
;
}
}
You can’t perform that action at this time.