Skip to content

Commit

Permalink
gha 5
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Feb 27, 2024
1 parent 2376975 commit 778be82
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 10 deletions.
31 changes: 26 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,31 @@ jobs:
steps:
- attach_workspace:
at: /workspace

- checkout

- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint

- *step_setup_git
- run: composer validate --ansi --strict
- run: composer install
- run: composer lint
- run: composer test

- run:
name: Validate composer.json
command: composer validate --ansi --strict

- run:
name: Install dependencies
command: composer install --ansi --no-progress --no-interaction --no-suggest --prefer-dist

- run:
name: Lint code
command: composer lint

- run:
name: Run tests
command: composer test

- persist_to_workspace:
root: /workspace
paths:
Expand All @@ -52,10 +68,13 @@ jobs:
steps:
- attach_workspace:
at: /workspace

- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint

- *step_setup_git

- checkout

# Test file will have a consistent name between deployments, but
Expand Down Expand Up @@ -108,7 +127,6 @@ jobs:
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
Expand All @@ -118,10 +136,13 @@ jobs:
steps:
- attach_workspace:
at: /workspace

- add_ssh_keys:
fingerprints:
- *deploy_ssh_fingerprint

- *step_setup_git

- checkout

# Test file will have a consistent name between deployments, but
Expand Down
119 changes: 114 additions & 5 deletions .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"

0 comments on commit 778be82

Please sign in to comment.