-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2376975
commit 778be82
Showing
2 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,13 +66,14 @@ jobs: | |
fail_ci_if_error: true | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
# Demonstration of deployment in 'force-push' mode. | ||
deploy-force-push: | ||
needs: test-php | ||
|
||
runs-on: ubuntu-latest | ||
|
||
env: | ||
BRANCH_NAME: ${{ github.head_ref }} | ||
GITHUB_BRANCH: ${{ github.head_ref }} | ||
|
||
steps: | ||
- name: Checkout code | ||
|
@@ -114,8 +115,8 @@ jobs: | |
# changes in the source repository. | ||
- name: Prepare test file. | ||
run: | | ||
export TEST_FILE="test-file--force-push--gha--${BRANCH_NAME//\//-}.txt" | ||
echo "Deployment 1 for branch $BRANCH_NAME" >> $TEST_FILE | ||
export TEST_FILE="test-file--force-push--gha--${GITHUB_BRANCH//\//-}.txt" | ||
echo "Deployment 1 for branch $GITHUB_BRANCH" >> $TEST_FILE | ||
date "+%Y%m%d-%H%M%S" >> $TEST_FILE | ||
- name: Deployment 1 | ||
|
@@ -136,8 +137,8 @@ jobs: | |
- name: Update the test file to simulate changes in the source repository. | ||
run: | | ||
export TEST_FILE="test-file--branch--gha--${BRANCH_NAME//\//-}.txt" | ||
echo "Deployment 2 for branch $BRANCH_NAME" >> $TEST_FILE | ||
export TEST_FILE="test-file--branch--gha--${GITHUB_BRANCH//\//-}.txt" | ||
echo "Deployment 2 for branch $GITHUB_BRANCH" >> $TEST_FILE | ||
date "+%Y%m%d-%H%M%S" >> $TEST_FILE | ||
- name: Deployment 2 | ||
|
@@ -154,3 +155,111 @@ jobs: | |
echo "Deployed to $DEPLOYED_BRANCH" | ||
echo | ||
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$TEST_FILE" | ||
# Demonstration of deployment in 'branch' mode. | ||
# Note that by design, pushing into the same branch will result in the failure | ||
# of the second push. This is because the mode is intended to create a new | ||
# branch per artifact deployment. | ||
deploy-branch: | ||
needs: test-php | ||
|
||
runs-on: ubuntu-latest | ||
|
||
env: | ||
GITHUB_BRANCH: ${{ github.head_ref }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
# Fetch all history for git repository. | ||
fetch-depth: 0 | ||
# Do not persist credentials after checkout | ||
# to allow to use custom credentials to push to a remote repo. | ||
persist-credentials: false | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Cache Composer dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/composer-cache | ||
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
|
||
- name: Setup SSH private key | ||
uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }} | ||
|
||
- name: Configure Git | ||
run: | | ||
git config --global user.name "${{ secrets.DEPLOY_USER_NAME }}" | ||
git config --global user.email "${{ secrets.DEPLOY_USER_EMAIL }}" | ||
- name: Install dependencies | ||
run: composer install | ||
|
||
# Test file will have a consistent name between deployments, but | ||
# the contents will be added to on each deployment to simulate | ||
# changes in the source repository. | ||
# Since each deployment in this mode creates a new branch, the test file | ||
# will be pushed to a new branch each time and won't be updated in | ||
# existing branches. | ||
|
||
- name: Prepare test file. | ||
run: | | ||
export TEST_FILE="test-file--branch--gha--${GITHUB_BRANCH//\//-}.txt" | ||
echo "Deployment 1 for branch $GITHUB_BRANCH" >> $TEST_FILE | ||
date "+%Y%m%d-%H%M%S" >> $TEST_FILE | ||
- name: Deployment 1 | ||
run: | | ||
vendor/bin/robo artifact \ | ||
[email protected]:drevops/git-artifact-destination.git \ | ||
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \ | ||
--mode=branch \ | ||
--report=$HOME/report--mode--branch.txt \ | ||
--push \ | ||
--debug | ||
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g') | ||
echo "Deployed to $DEPLOYED_BRANCH" | ||
echo | ||
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$TEST_FILE" | ||
rm $HOME/report--mode--branch.txt | ||
- name: Update the test file to simulate changes in the source repository. | ||
run: | | ||
export TEST_FILE="test-file--branch--gha--${GITHUB_BRANCH//\//-}.txt" | ||
echo "Deployment 2 for branch $GITHUB_BRANCH" >> $TEST_FILE | ||
date "+%Y%m%d-%H%M%S" >> $TEST_FILE | ||
- name: Deployment 2 - same branch | ||
run: | | ||
vendor/bin/robo artifact \ | ||
[email protected]:drevops/git-artifact-destination.git \ | ||
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \ | ||
--mode=branch \ | ||
--report=$HOME/report--mode--branch.txt \ | ||
--push \ | ||
--debug \ | ||
&& { echo "Expected to fail as repeated pushes to the same branch are not allowed, but succeeded" >&2; exit 1; } || echo "Failed as expected" | ||
- name: Deployment 2 - new branch | ||
run: | | ||
vendor/bin/robo artifact \ | ||
[email protected]:drevops/git-artifact-destination.git \ | ||
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i-s] \ | ||
--mode=branch \ | ||
--report=$HOME/report--mode--branch.txt \ | ||
--push \ | ||
--debug | ||
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g') | ||
echo "Deployed to $DEPLOYED_BRANCH" | ||
echo | ||
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$TEST_FILE" |