|
1 | 1 | name: 'Dump Context'
|
2 | 2 | description: 'Display context for action run'
|
3 | 3 |
|
| 4 | +outputs: |
| 5 | + # All github action outputs are strings, even if set to "true" |
| 6 | + # so when using these values always assert against strings or convert from json |
| 7 | + # \$\{{ needs.context.outputs.is_fork == 'true' }} // true |
| 8 | + # \$\{{ fromJson(needs.context.outputs.is_fork) == false }} // true |
| 9 | + # \$\{{ needs.context.outputs.is_fork == true }} // false |
| 10 | + # \$\{{ needs.context.outputs.is_fork }} // false |
| 11 | + is_fork: |
| 12 | + description: "" |
| 13 | + value: ${{ steps.context.outputs.is_fork }} |
| 14 | + is_default_branch: |
| 15 | + description: "" |
| 16 | + value: ${{ steps.context.outputs.is_default_branch }} |
| 17 | + is_release_master: |
| 18 | + description: "" |
| 19 | + value: ${{ steps.context.outputs.is_release_master }} |
| 20 | + is_release_tag: |
| 21 | + description: "" |
| 22 | + value: ${{ steps.context.outputs.is_release_tag }} |
| 23 | + # Hardcode image name |
| 24 | + image_name: |
| 25 | + description: "" |
| 26 | + value: mozilla/addons-server |
| 27 | + |
4 | 28 | runs:
|
5 | 29 | using: 'composite'
|
6 | 30 | steps:
|
|
36 | 60 | INPUTS_CONTEXT: ${{ toJson(inputs) }}
|
37 | 61 | run: |
|
38 | 62 | echo "$INPUTS_CONTEXT"
|
| 63 | +
|
| 64 | + - name: Set context |
| 65 | + id: context |
| 66 | + env: |
| 67 | + # The default branch of the repository, in this case "master" |
| 68 | + default_branch: ${{ github.event.repository.default_branch }} |
| 69 | + shell: bash |
| 70 | + run: | |
| 71 | + event_name="${{ github.event_name }}" |
| 72 | + event_action="${{ github.event.action }}" |
| 73 | +
|
| 74 | + # Stable check for if the workflow is running on the default branch |
| 75 | + # https://stackoverflow.com/questions/64781462/github-actions-default-branch-variable |
| 76 | + is_default_branch="${{ format('refs/heads/{0}', env.default_branch) == github.ref }}" |
| 77 | +
|
| 78 | + # In most events, the epository refers to the head which would be the fork |
| 79 | + is_fork="${{ github.event.repository.fork }}" |
| 80 | +
|
| 81 | + # This is different in a pull_request where we need to check the head explicitly |
| 82 | + if [[ "${{ github.event_name }}" == 'pull_request' ]]; then |
| 83 | + # repository on a pull request refers to the base which is always mozilla/addons-server |
| 84 | + is_head_fork="${{ github.event.pull_request.head.repo.fork }}" |
| 85 | + # https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions |
| 86 | + is_dependabot="${{ github.actor == 'dependabot[bot]' }}" |
| 87 | +
|
| 88 | + # If the head repository is a fork or if the PR is opened by dependabot |
| 89 | + # we consider the run to be a fork. Dependabot and proper forks are treated |
| 90 | + # the same in terms of limited read only github token scope |
| 91 | + if [[ "$is_head_fork" == 'true' || "$is_dependabot" == 'true' ]]; then |
| 92 | + is_fork="true" |
| 93 | + fi |
| 94 | + fi |
| 95 | +
|
| 96 | + is_release_master="false" |
| 97 | + is_release_tag="false" |
| 98 | +
|
| 99 | + # Releases can only happen if we are NOT on a fork |
| 100 | + if [[ "$is_fork" == 'false' ]]; then |
| 101 | + # A master release occurs on a push to the default branch of the origin repository |
| 102 | + if [[ "$event_name" == 'push' && "$is_default_branch" == 'true' ]]; then |
| 103 | + is_release_master="true" |
| 104 | + fi |
| 105 | +
|
| 106 | + # A tag release occurs when a release is published |
| 107 | + if [[ "$event_name" == 'release' && "$event_action" == 'publish' ]]; then |
| 108 | + is_release_tag="true" |
| 109 | + fi |
| 110 | + fi |
| 111 | +
|
| 112 | + echo "is_default_branch=$is_default_branch" >> $GITHUB_OUTPUT |
| 113 | + echo "is_fork=$is_fork" >> $GITHUB_OUTPUT |
| 114 | + echo "is_release_master=$is_release_master" >> $GITHUB_OUTPUT |
| 115 | + echo "is_release_tag=$is_release_tag" >> $GITHUB_OUTPUT |
| 116 | +
|
| 117 | + echo "event_name: $event_name" |
| 118 | + cat $GITHUB_OUTPUT |
0 commit comments