8
8
cwd :
9
9
description : Path to directory containing the checked out repository
10
10
default : ' .'
11
+ pr :
12
+ description : Whether or not to make a PR for the promotion
13
+ default : ' false'
14
+ token :
15
+ description : ' GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
16
+ default : ${{github.token}}
11
17
12
18
runs :
13
19
using : composite
18
24
DEST_DIR : ${{runner.temp}}/${{inputs.environment}}
19
25
run : |
20
26
TARGET_BRANCH=$(nix run '${{env.FLAKE}}#' -- info '${{inputs.cwd}}#${{inputs.environment}}' --json | jq -r .branch)
27
+ PR_BRANCH="promote/$TARGET_BRANCH"
21
28
22
29
if git -C "${{inputs.cwd}}" fetch origin "$TARGET_BRANCH"; then
23
30
git -C "${{inputs.cwd}}" worktree add --checkout "${{env.DEST_DIR}}" "$TARGET_BRANCH"
@@ -29,13 +36,31 @@ runs:
29
36
30
37
rsync --recursive --delete --exclude=.git -L "$RESULT/" "${{env.DEST_DIR}}"
31
38
32
- echo "BRANCH=$TARGET_BRANCH" >> "$GITHUB_ENV"
39
+ if [[ "${{inputs.pr}}" == "true" ]]; then
40
+ git -C "${{env.DEST_DIR}}" checkout -B "$PR_BRANCH"
41
+ echo "BRANCH=$PR_BRANCH" >> "$GITHUB_ENV"
42
+ echo "FORCE=--force" >> "$GITHUB_ENV"
43
+ else
44
+ echo "BRANCH=$TARGET_BRANCH" >> "$GITHUB_ENV"
45
+ echo "FORCE=" >> "$GITHUB_ENV"
46
+ fi
47
+
48
+ echo "TARGET_BRANCH=$TARGET_BRANCH" >> "$GITHUB_ENV"
33
49
echo "DEST_DIR=$(realpath --relative-to "$PWD" "$DEST_DIR")" >> "$GITHUB_ENV"
50
+ echo "COMMIT_MESSAGE=chore(${{inputs.environment}}): promote to ${{inputs.environment}} ${{github.sha}}" >> "$GITHUB_ENV"
34
51
35
52
- uses : EndBug/add-and-commit@v9
36
53
with :
37
54
cwd : ${{env.DEST_DIR}}
38
55
default_author : github_actions
39
- message : " chore( ${{inputs.environment}}): promote to ${{inputs.environment}} ${{github.sha}} "
56
+ message : ${{env.COMMIT_MESSAGE}}
40
57
fetch : false
41
- push : --set-upstream origin ${{env.BRANCH}}
58
+ push : --set-upstream origin ${{env.BRANCH}} ${{env.FORCE}}
59
+
60
+ - uses : thomaseizinger/create-pull-request@1.4.0
61
+ if : inputs.pr == 'true'
62
+ with :
63
+ github_token : ${{inputs.token}}
64
+ head : ${{env.BRANCH}}
65
+ base : ${{env.TARGET_BRANCH}}
66
+ title : ${{env.COMMIT_MESSAGE}}
0 commit comments