Skip to content

Commit

Permalink
fix: more CI fixes (#439)
Browse files Browse the repository at this point in the history
* fix: use token with release-please to trigger future workflows

* fix: prod deploy PR depends on deploy to staging
  • Loading branch information
SgtPooki authored Nov 11, 2024
1 parent 42c9a90 commit b5e0e25
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 68 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Auto release PR

on:
push:
tags:
- '*'
workflow_dispatch:

permissions:
contents: write # to create release
pull-requests: write # to create release PR

jobs:
# from https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another
deploy-staging:
runs-on: ubuntu-latest
permissions:
pull-requests: write # to create release PR
steps:
- uses: actions/checkout@v4
with:
ref: staging
- name: Fetch all tags
run: git fetch --tags
- name: Get latest tag
id: get_latest_tag
run: echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
- name: Checkout latest tag
run: git checkout ${{ steps.get_latest_tag.outputs.tag }}
- name: Ensure staging-release branch points to latest tag
run: |
git checkout -B staging-release ${{ steps.get_latest_tag.outputs.tag }}
git push origin staging-release --force
- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
token: ${{ secrets.UCI_GITHUB_TOKEN }}
base: staging
branch: staging-release
title: 'chore: point staging to release ${{ steps.get_latest_tag.outputs.tag }}'
body: 'This PR points the staging branch to release ${{ steps.get_latest_tag.outputs.tag }}.'

# from https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another
deploy-production:
runs-on: ubuntu-latest
permissions:
pull-requests: write # to create release PR
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history so that git commands work correctly
- name: Fetch all branches and tags
run: |
git fetch --all --tags
- name: Get latest tag merged into staging
id: get_latest_tag
run: |
git checkout origin/staging
latest_tag=$(git describe --tags $(git rev-list --tags --merged origin/staging --max-count=1))
echo "tag=$latest_tag" >> $GITHUB_OUTPUT
- name: Checkout latest tag
run: git checkout ${{ steps.get_latest_tag.outputs.tag }}
- name: Ensure production-release branch points to latest tag
run: |
git checkout -B production-release ${{ steps.get_latest_tag.outputs.tag }}
git push origin production-release --force
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7.0.5
with:
token: ${{ secrets.UCI_GITHUB_TOKEN }}
base: production
branch: production-release
title: 'chore: Point production to release ${{ steps.get_latest_tag.outputs.tag }}'
body: 'This PR points the production branch to release ${{ steps.get_latest_tag.outputs.tag }}.'

71 changes: 3 additions & 68 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,71 +176,6 @@ jobs:
- uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4.1.3
with:
release-type: node

debugging-stuff:
runs-on: ubuntu-latest
needs: [ release-please ]
steps:
- name: debugging
run: |
# output the release-please action outputs
echo "release-please outputs: ${{ toJson(needs.release-please.outputs) }}"
deploy-staging:
runs-on: ubuntu-latest
needs: [ build, check, release-please ]
if: ((github.event_name == 'workflow_dispatch' || github.event_name == 'push') && github.ref == 'refs/heads/main' && needs.release-please.outputs.releases_created == 'true')
permissions:
pull-requests: write # to create release PR
steps:
- uses: actions/checkout@v4
with:
ref: staging
- name: Fetch all tags
run: git fetch --tags
- name: Get latest tag
id: get_latest_tag
run: echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
- name: Checkout latest tag
run: git checkout ${{ steps.get_latest_tag.outputs.tag }}
- name: Ensure staging-release branch points to latest tag
run: |
git checkout -B staging-release ${{ steps.get_latest_tag.outputs.tag }}
git push origin staging-release --force
- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
base: staging
branch: staging-release
title: 'chore: point staging to release ${{ steps.get_latest_tag.outputs.tag }}'
body: 'This PR points the staging branch to release ${{ steps.get_latest_tag.outputs.tag }}.'

# from https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another
deploy-production:
runs-on: ubuntu-latest
needs: [ build, check, release-please ]
if: ((github.event_name == 'workflow_dispatch' || github.event_name == 'push') && github.ref == 'refs/heads/main' && needs.release-please.outputs.releases_created == 'true')
permissions:
pull-requests: write # to create release PR
steps:
- uses: actions/checkout@v4
with:
ref: production
- name: Fetch all tags
run: git fetch --tags
- name: Get latest tag
id: get_latest_tag
run: echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
- name: Checkout latest tag
run: git checkout ${{ steps.get_latest_tag.outputs.tag }}
- name: Ensure production-release branch points to latest tag
run: |
git checkout -B production-release ${{ steps.get_latest_tag.outputs.tag }}
git push origin production-release --force
- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
base: production
branch: production-release
title: 'chore: Point production to release ${{ steps.get_latest_tag.outputs.tag }}'
body: 'This PR points the production branch to release ${{ steps.get_latest_tag.outputs.tag }}.'
# Use a token for creating the release-pr and git tags so that the `deploy` workflow can be triggered by them
# see https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs and https://github.com/orgs/community/discussions/27028 for more information
token: ${{ secrets.UCI_GITHUB_TOKEN }}

0 comments on commit b5e0e25

Please sign in to comment.