Fixed resulting branch in CI examples. #35
Workflow file for this run
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
name: Test PHP | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
- 'feature/**' | |
jobs: | |
test-php: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
php-versions: ['8.1', '8.2', '8.3'] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- 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 | |
- name: Check coding standards | |
run: composer lint | |
- name: Run tests | |
run: XDEBUG_MODE=coverage composer test | |
- name: Upload coverage report as an artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{github.job}}-code-coverage-report-${{ matrix.php-versions }} | |
path: ./.coverage-html | |
- name: Upload coverage report to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
files: ./cobertura.xml | |
fail_ci_if_error: true | |
token: ${{ secrets.CODECOV_TOKEN }} | |
deploy-force-push: | |
needs: test-php | |
runs-on: ubuntu-latest | |
env: | |
BRANCH_NAME: ${{ 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. | |
- 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 | |
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--force-push--gha--[branch] \ | |
--mode=force-push \ | |
--report=$HOME/report--mode--force-push.txt \ | |
--push \ | |
--debug | |
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.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--force-push.txt | |
- 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 | |
date "+%Y%m%d-%H%M%S" >> $TEST_FILE | |
- name: Deployment 2 | |
run: | | |
vendor/bin/robo artifact \ | |
[email protected]:drevops/git-artifact-destination.git \ | |
--branch=mode--force-push--gha--[branch] \ | |
--mode=force-push \ | |
--report=$HOME/report--mode--force-push.txt \ | |
--push \ | |
--debug | |
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.txt | sed 's/ //g') | |
echo "Deployed to $DEPLOYED_BRANCH" | |
echo | |
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$TEST_FILE" |