testing env variables #87
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
# This workflow will build a golang project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
name: test-and-publish-version-dev | |
on: | |
push: | |
branches-ignore: | |
- main | |
env: | |
MONGO_USER: ${{ vars.MONGO_USER }} | |
MONGO_PASSWORD: ${{ vars.MONGO_PASSWORD }} | |
MONGO_DB: ${{ vars.MONGO_DB }} | |
MONGO_PORT: ${{ vars.MONGO_PORT }} | |
jobs: | |
test: | |
environment: Development | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: [ '1.22.x' ] | |
steps: | |
- uses: actions/setup-go@v5 | |
with: | |
# Semantic version range syntax or exact version of Go | |
go-version: ${{ matrix.go-version }} | |
- uses: actions/checkout@v3 | |
- uses: satackey/[email protected] | |
continue-on-error: true | |
- name: Create env file | |
run: echo "MONGO_USER=${{ env.MONGO_USER }}" >> .env && echo "MONGO_PASSWORD=${{ env.MONGO_PASSWORD }}" >> .env && echo "MONGO_DB=${{ env.MONGO_DB }}" >> .env && echo "MONGO_PORT=${{ env.MONGO_PORT }}" >> .env | |
- name: Set database running | |
uses: supercharge/[email protected] | |
with: | |
mongodb-username: ${{ env.MONGO_USER }} | |
mongodb-password: ${{ env.MONGO_PASSWORD }} | |
mongodb-db: ${{ env.MONGO_DB }} | |
mongodb-port: ${{ env.MONGO_PORT }} | |
- name: Run tests | |
run: go test -v ./... | |
build: | |
environment: Development | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: [ '1.22.x' ] | |
needs: test | |
steps: | |
- uses: actions/checkout@v3 | |
# Read version from file | |
- name: Read version | |
id: version | |
run: echo ::set-output name=version::$(cat version.config) | |
# Read date in format YYYYMMDDHHMMSS | |
- name: Read date | |
id: date | |
run: echo ::set-output name=date::$(date +"%Y%m%d%H%M%S") | |
# Read branch name | |
- name: Read branch name | |
id: branch | |
run: echo ::set-output name=branch::${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | |
# Set up Go | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ matrix.go-version }} | |
# Create tag with version, date and branch | |
- name: Create tag | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/${{ steps.version.outputs.version }}-${{ steps.date.outputs.date }}-${{ steps.branch.outputs.branch }}', | |
sha: context.sha | |
}) |