aboutsummaryrefslogtreecommitdiff
path: root/.github/actions/openvic2-env/action.yml
blob: 245777d5c4ea46ce4693c8bc0aaca2c3cf5d96c3 (plain) (blame)
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
name: Setup OpenVic2 Environment
description: Setup OpenVic2 Environment
runs:
    using: "composite"
    steps:
        - name: Setup Environment
          uses: actions/github-script@v6
          with:
            script: |
                const commit_name = 'OPENVIC2_COMMIT';
                const tag_name = 'OPENVIC2_TAG';
                const release_name = 'OPENVIC2_RELEASE';
                var commit_sha = process.env["GITHUB_SHA"];
                if(context.eventName === 'pull_request') {
                    commit_sha = context.payload.pull_request.head.sha;
                }
                core.exportVariable(commit_name, commit_sha);
                try {
                  const release = await github.rest.repos.getLatestRelease({owner: context.repo.owner, repo: context.repo.repo});
                  core.exportVariable(tag_name, release.data["tag_name"]);
                  core.exportVariable(release_name, release.data["name"]);
                } catch(error) {
                  if (error.response.status != 404) throw error;
                  const tagList = await github.rest.repos.listTags({owner: context.repo.owner, repo: context.repo.repo});
                  core.exportVariable(tag_name, tagList.data[0].name);
                  core.exportVariable(release_name, tagList.data[0].name);
                }