Update README.md #9
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 data and merge to production | |
on: | |
push: | |
branches: main | |
env: | |
GITHUB_TOKEN: ${{ secrets.CI_TOKEN }} | |
MERGE_FROM_BRANCH: main | |
MERGE_TO_BRANCH: production | |
jobs: | |
tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install Hakai Tests | |
run: | | |
python -m pip install --upgrade pip | |
pip install git+https://HakaiInstitute:[email protected]/HakaiInstitute/hakai-datasets-repo-standard-tests.git | |
- name: Test with pytest | |
run: | | |
pytest --pyargs hakai_data_repo_tests | |
production-merge: | |
runs-on: ubuntu-latest | |
env: | |
PR_STATUS: '' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set PR status as environment variable | |
run: | | |
echo 'PR_STATUS<<EOF' >> $GITHUB_ENV | |
gh pr status >> $GITHUB_ENV | |
echo 'EOF' >> $GITHUB_ENV | |
- name: Create MERGE_TO_BRANCH if it does not exist | |
run: | | |
git checkout -b ${{env.MERGE_TO_BRANCH}} | |
git push origin ${{env.MERGE_TO_BRANCH}} | |
- name: Compare branches and save to environment variable | |
run: | | |
git fetch origin ${{env.MERGE_FROM_BRANCH}} | |
git fetch origin ${{env.MERGE_TO_BRANCH}} | |
BRANCHES_DIFF=$(git diff --name-only origin/${{env.MERGE_FROM_BRANCH}} origin/${{env.MERGE_TO_BRANCH}}) | |
echo "BRANCHES_DIFF<<EOF" >> $GITHUB_ENV | |
echo $BRANCHES_DIFF >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Create Pull Request if there are changes | |
if: ${{contains(env.PR_STATUS, 'There is no pull request associated with [main]')}} && ${{env.BRANCHES_DIFF != ''}} | |
run: | | |
gh pr create \ | |
-H ${{env.MERGE_FROM_BRANCH}} \ | |
-B ${{env.MERGE_TO_BRANCH}} \ | |
--title "Merge latest changes to main into production branch" \ | |
--body-file ".github/PULL_REQUEST_TEMPLATE/production-merge-pull-request-body.md" | |
merge: | |
runs-on: ubuntu-latest | |
needs: [tests, production-merge] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Auto-merge pull requests | |
run: gh pr merge --auto --merge |