Skip to content

Commit 6c0643c

Browse files
authored
Merge pull request #9 from arnarg/update-action
Update github action to support PRs
2 parents c946840 + 530ca0e commit 6c0643c

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

action.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ inputs:
88
cwd:
99
description: Path to directory containing the checked out repository
1010
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}}
1117

1218
runs:
1319
using: composite
@@ -18,6 +24,7 @@ runs:
1824
DEST_DIR: ${{runner.temp}}/${{inputs.environment}}
1925
run: |
2026
TARGET_BRANCH=$(nix run '${{env.FLAKE}}#' -- info '${{inputs.cwd}}#${{inputs.environment}}' --json | jq -r .branch)
27+
PR_BRANCH="promote/$TARGET_BRANCH"
2128
2229
if git -C "${{inputs.cwd}}" fetch origin "$TARGET_BRANCH"; then
2330
git -C "${{inputs.cwd}}" worktree add --checkout "${{env.DEST_DIR}}" "$TARGET_BRANCH"
@@ -29,13 +36,31 @@ runs:
2936
3037
rsync --recursive --delete --exclude=.git -L "$RESULT/" "${{env.DEST_DIR}}"
3138
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"
3349
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"
3451
3552
- uses: EndBug/add-and-commit@v9
3653
with:
3754
cwd: ${{env.DEST_DIR}}
3855
default_author: github_actions
39-
message: "chore(${{inputs.environment}}): promote to ${{inputs.environment}} ${{github.sha}}"
56+
message: ${{env.COMMIT_MESSAGE}}
4057
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

Comments
 (0)