Skip to content

Commit

Permalink
Merge pull request #680 from basedosdados/chore/update-gh-actions
Browse files Browse the repository at this point in the history
chore: update deployment workflows to use fixed branch references
  • Loading branch information
jhonylucas74 authored Sep 19, 2024
2 parents d0c2da2 + 10fd95f commit f89425e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 59 deletions.
35 changes: 1 addition & 34 deletions .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
workflows: [Release Image (Development)]
branches: [dev]
types: [completed]
workflow_dispatch:
jobs:
deploy-dev:
runs-on: ubuntu-latest
Expand All @@ -16,42 +15,10 @@ jobs:
name: development
url: https://api.development.basedosdados.org
steps:
- name: Download branch name
uses: actions/github-script@v6
if: ${{ github.event_name == 'workflow_run' }}
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "branch"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifact.zip`, Buffer.from(download.data));
- name: Extract branch name
if: ${{ github.event_name == 'workflow_run' }}
run: unzip artifact.zip
- name: Read branch name
id: extract_branch
run: |
if [ ! -f "branch" ]; then
echo "branch=main" >> "$GITHUB_OUTPUT"
else
echo "branch=$(cat branch)" >> "$GITHUB_OUTPUT"
fi
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.extract_branch.outputs.branch }}
ref: dev
- name: Import secrets from Vault
id: import_secrets
uses: hashicorp/[email protected]
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
workflows: [Release Image (Production)]
branches: [main]
types: [completed]
workflow_dispatch:
jobs:
deploy-prod:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
ref: staging
- name: Import secrets from Vault
id: import_secrets
uses: hashicorp/[email protected]
Expand Down
24 changes: 2 additions & 22 deletions .github/workflows/release-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,11 @@ jobs:
release-docker:
name: Release Image
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
contains(github.event.pull_request.labels.*.name, 'preview')
steps:
- name: Select branch
id: select_branch
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "branch=main" >> $GITHUB_OUTPUT
else
echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT
fi
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ steps.select_branch.outputs.branch }}
ref: dev
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
Expand All @@ -43,13 +32,4 @@ jobs:
org.opencontainers.image.revision=${{ github.sha }}
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Save branch name artifact
run: |
mkdir -p ./branch
echo -n ${{ steps.select_branch.outputs.branch }} > ./branch/branch
- name: Upload branch name artifact
uses: actions/upload-artifact@v3
with:
name: branch
path: branch/
retention-days: 1
2 changes: 1 addition & 1 deletion .github/workflows/release-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
ref: staging
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
Expand Down

0 comments on commit f89425e

Please sign in to comment.