Add GitHub Actions workflow for Python package publishing#5019
Add GitHub Actions workflow for Python package publishing#5019wyeditthea wants to merge 1 commit intoethereum:masterfrom
Conversation
This workflow automates the process of uploading a Python package to PyPI upon release creation, including steps for building and publishing the package.
wyeditthea
left a comment
There was a problem hiding this comment.
Managing GitHub Actions settings for a repository
You can disable or configure GitHub Actions for a specific repository.
About GitHub Actions permissions for your repository
By default, GitHub Actions is enabled on all repositories and organizations. You can choose to disable GitHub Actions or limit it to actions and reusable workflows in your organization. For more information about GitHub Actions, see Writing workflows.
You can enable GitHub Actions for your repository. When you enable GitHub Actions, workflows are able to run actions and reusable workflows located within your repository and any other public repository. You can disable GitHub Actions for your repository altogether. When you disable GitHub Actions, no workflows run in your repository.
Alternatively, you can enable GitHub Actions in your repository but limit the actions and reusable workflows a workflow can run.
Managing GitHub Actions permissions for your repository
You can disable GitHub Actions for a repository, or set a policy that configures which actions and reusable workflows can be used in the repository.
Note
You might not be able to manage these settings if your organization has an overriding policy or is managed by an enterprise that has overriding policy. For more information, see Disabling or limiting GitHub Actions for your organization or Enforcing policies for GitHub Actions in your enterprise.
-
On GitHub, navigate to the main page of the repository.
-
Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.
-
In the left sidebar, click Actions, then click General.
-
Under "Actions permissions", select an option.
If you choose Allow OWNER, and select non-OWNER, actions and reusable workflows, actions and reusable workflows within your organization are allowed, and there are additional options for allowing other specific actions and reusable workflows. For more information, see Allowing select actions and reusable workflows to run.
When you allow actions and reusable workflows from only in your organization, the policy blocks all access to actions authored by GitHub. For example, the
actions/checkoutaction would not be accessible.When you enable Require actions to be pinned to a full-length commit SHA, all actions must be pinned to a full-length commit SHA to be used. This includes actions from your organization and actions authored by GitHub. Reusable workflows can still be referenced by tag. For more information, see Secure use reference.
-
Click Save.
Allowing select actions and reusable workflows to run
When you choose Allow OWNER, and select non-OWNER, actions and reusable workflows, local actions and reusable workflows are allowed, and there are additional options for allowing other specific actions and reusable workflows:
Note
You might not be able to manage these settings if your organization has an overriding policy or is managed by an enterprise that has overriding policy. For more information, see Disabling or limiting GitHub Actions for your organization or Enforcing policies for GitHub Actions in your enterprise.
-
Allow actions created by GitHub: You can allow all actions created by GitHub to be used by workflows. Actions created by GitHub are located in the
actionsandgithuborganizations. For more information, see theactionsandgithuborganizations. -
Allow Marketplace actions by verified creators: You can allow all GitHub Marketplace actions created by verified creators to be used by workflows. When GitHub has verified the creator of the action as a partner organization, the badge is displayed next to the action in GitHub Marketplace.
-
Allow or block specified actions and reusable workflows: You can restrict workflows to use actions and reusable workflows in specific organizations and repositories. Specified actions cannot be set to more than 1000.
To restrict access to specific tags or commit SHAs of an action or reusable workflow, use the same syntax used in the workflow to select the action or reusable workflow.
- For an action, the syntax is
OWNER/REPOSITORY@TAG-OR-SHA. For example, useactions/javascript-action@v1.0.1to select a tag oractions/javascript-action@a824008085750b8e136effc585c3cd6082bd575fto select a SHA. For more information, see Using pre-written building blocks in your workflow. - For a reusable workflow, the syntax is
OWNER/REPOSITORY/PATH/FILENAME@TAG-OR-SHA. For example,octo-org/another-repo/.github/workflows/workflow.yml@v1. For more information, see Reuse workflows.
You can use the
*wildcard character to match patterns. For example, to allow all actions and reusable workflows in organizations that start withspace-org, you can specifyspace-org*/*. To allow all actions and reusable workflows in repositories that start with octocat, you can use*/octocat**@*. For more information about using the*wildcard, see Workflow syntax for GitHub Actions.Use
,to separate patterns. For example, to allow all actions and reusable workflows from theoctocatandoctokitorganizations, you can specifyoctocat/*, octokit/*.Use the
!prefix to block patterns. For example, to allow all actions and reusable workflows from thespace-orgorganization, but block a specific action likespace-org/action, you can specifyspace-org/*, !space-org/action@*. By default, only actions and reusable workflows specified in the list will be allowed. To allow all actions and reusable workflows while also blocking specific actions, you can specify*, !space-org/action@*. - For an action, the syntax is
This procedure demonstrates how to add specific actions and reusable workflows to the list.
-
On GitHub, navigate to the main page of the repository.
-
Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.
-
In the left sidebar, click Actions, then click General.
-
Under "Actions permissions", select Allow OWNER, and select non-OWNER, actions and reusable workflows and add your required actions to the list.
-
Click Save.
Controlling changes from forks to workflows in public repositories
Anyone can fork a public repository, and then submit a pull request that proposes changes to the repository's GitHub Actions workflows. Although workflows from forks do not have access to sensitive data such as secrets, they can be an annoyance for maintainers if they are modified for abusive purposes.
To help prevent this, workflows on pull requests to public repositories from some outside contributors will not run automatically, and might need to be approved first. Depending on the "Approval for running fork pull request workflows from contributors" setting, workflows on pull requests to public repositories will not run automatically and may need approval if:
- The pull request is created by a user that requires approvals based on the selected policy.
- The pull request event is triggered by a user that requires approvals based on the selected policy.
By default, all first-time contributors require approval to run workflows.
Workflows triggered by pull_request_target events are run in the context of the base branch. Since the base branch is considered trusted, workflows triggered by these events will always run, regardless of approval settings. For more information about the pull_request_target event, see Events that trigger workflows.
[!WARNING] These workflow approval policies are intended to restrict the set of users that can execute workflows in GitHub Actions runners that could lead to unexpected resource and compute consumption when using GitHub-hosted runners. If you are using self-hosted runners, potentially malicious user-controlled workflow code will execute automatically if the user is allowed to bypass approval in the set approval policy or if the pull request is approved. You must consider the risk of executing this code in your infrastructure and should review and follow the self-hosted runner security recommendations regardless of the approval settings utilized. See Secure use reference.
You can configure this behavior for a repository using the procedure below. Modifying this setting overrides the configuration set at the organization or enterprise level.
-
On GitHub, navigate to the main page of the repository.
-
Under your repository name, click **<path d="M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.103-.303c.644-.176 1.392.021 1.82.63.27.385.506.792.704 1.218.315.675.111 1.422-.364 1.891l-.814.806c-.049.048-.098.147-.088.294.016.257.016.515 0 .772-.01.147.038.246.088.294l.814.806c.475.469.679 1.216.364 1.891a7.977 7.977 0 0 1-.704 1.217c-.428.61-1.176.807-1.82.63l-1.102-.302c-.067-.019-.177-.011-.3.071a5.909 5.909 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.106c-.168.646-.715 1.196-1.458 1.26a8.006 8.006 0 0 1-1.402 0c-.743-.064-1.289-.614-1.458-1.26l-.289-1.106c-.018-.066-.079-.158-.212-.224a5.738 5.738 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.103.303c-.644.176-1.392-.021-1.82-.63a8.12 8.12 0 0 1-.704-1.218c-.315-.675-.111-1.422.363-1.891l.815-.806c.05-.048.098-.147.088-.294a6.214 6.214 0 0 1 0-.772c.01-.147-.038-.246-.088-.294l-.815-.806C.635 6.045.431 5.298.746 4.623a7.92 7.92 0 0 1 .704-1.217c.428-.61 1.176-.807 1.82-.63l1.102.302c.067.019.177.011.3-.071.214-.143.437-.272.668-.386.133-.066.194-.158.211-.224l.29-1.106C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm-.571 1.525c-.036.003-.108.036-.137.146l-.289 1.105c-.147.561-.549.967-.998 1.189-.173.086-.34.183-.5.29-.417.278-.97.423-1.529.27l-1.103-.303c-.109-.03-.175.016-.195.045-.22.312-.412.644-.573.99-.014.031-.021.11.059.19l.815.806c.411.406.562.957.53 1.456a4.709 4.709 0 0 0 0 .582c.032.499-.119 1.05-.53 1.456l-.815.806c-.081.08-.073.159-.059.19.162.346.353.677.573.989.02.03.085.076.195.046l1.102-.303c.56-.153 1.113-.008 1.53.27.161.107.328.204.501.29.447.222.85.629.997 1.189l.289 1.105c.029.109.101.143.137.146a6.6 6.6 0 0 0 1.142 0c.036-.003.108-.036.137-.146l.289-1.105c.147-.561.549-.967.998-1.189.173-.086.34-.183.5-.29.417-.278.97-.423 1.529-.27l1.103.303c.109.029.175-.016.195-.045.22-.313.411-.644.573-.99.014-.031.021-.11

This workflow automates the process of uploading a Python package to PyPI upon release creation, including steps for building and publishing the package.